log

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultCaller is a Valuer that returns the file and line.
	DefaultCaller = Caller(4)

	// DefaultTimestamp is a Valuer that returns the current wallclock time.
	DefaultTimestamp = Timestamp(time.RFC3339)
)
View Source
var (
	ZapMaxSize    = 10   //每个日志文件保存多少M,默认10M
	ZapMaxBackUps = 30   //保留多少个备份,默认不限
	ZapMaxAge     = 7    //保留多少天,默认不限
	ZapCompress   = true //是否压缩
	ZapLocalTime  = true //是否使用localTime

)
View Source
var DefaultMessageKey = "msg"
View Source
var LogCat *logcat

Functions

func Debug

func Debug(a ...interface{})

Debug logs a message at debug level.

func Debugf

func Debugf(format string, a ...interface{})

Debugf logs a message at debug level.

func Debugw

func Debugw(keyvals ...interface{})

Debugw logs a message at debug level.

func DefaultZapEncoder

func DefaultZapEncoder() zapcore.Encoder

*

  • 默认编码器

func Error

func Error(a ...interface{})

Error logs a message at error level.

func Errorf

func Errorf(format string, a ...interface{})

Errorf logs a message at error level.

func Errorw

func Errorw(keyvals ...interface{})

Errorw logs a message at error level.

func Fatal

func Fatal(a ...interface{})

Fatal logs a message at fatal level.

func Fatalf

func Fatalf(format string, a ...interface{})

Fatalf logs a message at fatal level.

func Fatalw

func Fatalw(keyvals ...interface{})

Fatalw logs a message at fatal level.

func GetCommonLog

func GetCommonLog(level Level, encoder zapcore.Encoder, ws ...zapcore.WriteSyncer) *zap.Logger

func GetEasyModeLog

func GetEasyModeLog(level Level, maxsize, maxBackups, maxAge int, compress, localTime bool) *zap.Logger

简易模式设置

func GetLogFilePath

func GetLogFilePath(storagePath string, levelName string) string

根据存储路径和日志级别获取完整的日志文件路径

func GetZapWriter

func GetZapWriter(path string, maxsize, maxBackups, maxAge int, compress, localTime bool) io.Writer

func Info

func Info(a ...interface{})

Info logs a message at info level.

func Infof

func Infof(format string, a ...interface{})

Infof logs a message at info level.

func Infow

func Infow(keyvals ...interface{})

Infow logs a message at info level.

func Log

func Log(level Level, keyvals ...interface{})

func NewLogger

func NewLogger(l Logger, opts ...Option) *logcat

创建日志结构体

func SetLogger

func SetLogger(logger Logger)

func Value

func Value(ctx context.Context, v interface{}) interface{}

Value return the function value.

func Warn

func Warn(a ...interface{})

Warn logs a message at warn level.

func Warnf

func Warnf(format string, a ...interface{})

Warnf logs a message at warnf level.

func Warnw

func Warnw(keyvals ...interface{})

Warnw logs a message at warnf level.

Types

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

func NewFilter

func NewFilter(logger Logger, opts ...FilterOption) *Filter

func (*Filter) Log

func (f *Filter) Log(level Level, keyvals ...interface{}) error

type FilterOption

type FilterOption func(*Filter)

func FilterFunc

func FilterFunc(f func(level Level, keyvals ...interface{}) bool) FilterOption

FilterFunc with filter func.

func FilterKey

func FilterKey(key ...string) FilterOption

FilterKey with filter key.

func FilterLevel

func FilterLevel(level Level) FilterOption

func FilterValue

func FilterValue(value ...string) FilterOption

FilterValue with filter value.

type Level

type Level int
const (
	LevelDebug Level = iota - 1
	// LevelInfo is logger info level.
	LevelInfo
	// LevelWarn is logger warn level.
	LevelWarn
	// LevelError is logger error level.
	LevelError
	// LevelFatal is logger fatal level
	LevelFatal
)

func (Level) String

func (l Level) String() string

func (Level) ToZapLevel

func (l Level) ToZapLevel() zapcore.Level

type Logger

type Logger interface {
	Log(level Level, keyvals ...interface{}) error
}

实现默认接口

func With

func With(l Logger, kv ...interface{}) Logger

func WithContext

func WithContext(ctx context.Context, l Logger) Logger

WithContext returns a shallow copy of l with its context changed to ctx. The provided ctx must be non-nil.

type Option

type Option func(*logcat)

func WithMessageKey

func WithMessageKey(k string) Option

设置默认messageKey

type Valuer

type Valuer func(ctx context.Context) interface{}

Valuer is returns a log value.

func Caller

func Caller(depth int) Valuer

Caller returns a Valuer that returns a pkg/file:line description of the caller.

func Timestamp

func Timestamp(layout string) Valuer

Timestamp returns a timestamp Valuer with a custom time format.

type ZapLogger

type ZapLogger struct {
	// contains filtered or unexported fields
}
	MaxSize         每个日志文件保存多少M,默认10M
	MaxBackups      保留多少个备份,默认不限
    MaxAge          保留多少天,默认不限
    Compress        是否压缩
    LocalTime       是否使用localTime
    FileStoragePath 日志文件存放路径

func NewZapLogger

func NewZapLogger(opts ...ZapOption) *ZapLogger

func (*ZapLogger) Close

func (l *ZapLogger) Close() error

func (*ZapLogger) Log

func (z *ZapLogger) Log(level Level, keyvals ...interface{}) error

func (*ZapLogger) Sync

func (l *ZapLogger) Sync() error

type ZapOption

type ZapOption func(options *ZapLogger)

func WithCompress

func WithCompress(compress bool) ZapOption

func WithEnableEasyMode

func WithEnableEasyMode(enable bool) ZapOption

func WithEncoder

func WithEncoder(encoder zapcore.Encoder) ZapOption

func WithLevel

func WithLevel(level Level) ZapOption

func WithMaxAge

func WithMaxAge(maxAge int) ZapOption

func WithMaxBackups

func WithMaxBackups(maxBackups int) ZapOption

func WithMaxSize

func WithMaxSize(maxSize int) ZapOption

func WithWriteSyncer

func WithWriteSyncer(writeSyncers ...zapcore.WriteSyncer) ZapOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL