log

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 10 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 DefaultMessageKey = "msg"
View Source
var LogCat *logcat

Functions

func BuildDefaultLog added in v1.2.0

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

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 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
}

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 WithLevel

func WithLevel(level Level) ZapOption

func WithZapLogger added in v1.2.0

func WithZapLogger(logger *zap.Logger) ZapOption

func WithZapMsgKey added in v1.2.0

func WithZapMsgKey(k string) ZapOption

Jump to

Keyboard shortcuts

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