logger

package
v1.1.23 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Log = Manager.Log
View Source
var Sugar = Manager.Sugar

Functions

func SetDevelopment added in v1.0.2

func SetDevelopment(enable bool)

func SetLevel added in v1.0.2

func SetLevel(level any)

func WrapCore

func WrapCore(core zapcore.Core) zapcore.Core

WrapCore wraps a Core and runs a collection of user-defined callback hooks each time a message is logged. Execution of the callbacks is blocking.

This offers users an easy way to register simple callbacks (e.g., metrics collection) without implementing the full Core interface.

Types

type LoaderFactory

type LoaderFactory struct {
	// ConfLoader.Reload 的包装函数
	ReloadApply func(key string, confStruct interface{})
	// ConfLoader.Provide 的包装函数
	ProvideApply func() (key string, confStruct interface{})
}

LoaderFactory ConfLoader 工厂,用于生成需要动态包装的 ConfLoader 实现

@implement ConfLoader

func (LoaderFactory) Provide

func (l LoaderFactory) Provide() (key string, confStruct interface{})

func (LoaderFactory) Reload

func (l LoaderFactory) Reload(key string, confStruct interface{})

type LogConf

type LogConf struct {
	Development bool
	Level       string
}

type Logger

type Logger struct {
	Log   *zap.Logger
	Sugar *zap.SugaredLogger
	Level zap.AtomicLevel
	// contains filtered or unexported fields
}

Logger 具体Log的持有类

func NewLogger

func NewLogger(cfg zap.Config, opts ...Option) *Logger

func (*Logger) ReloadFactory

func (l *Logger) ReloadFactory(k string, onReloadeds ...func()) LoaderFactory

func (*Logger) SetDevelopment

func (l *Logger) SetDevelopment(enable bool)

SetDevelopment 是否开启开发者模式 true为development mode 否则为production mode

development mode: zap.NewDevelopmentConfig()模式
production mode:zap.NewProductionConfig()模式
@receiver l
@param enable

func (*Logger) SetLevel

func (l *Logger) SetLevel(level any)

SetLevel 动态改变打印级别

@param level 支持的类型为 int,int8,zapcore.Level,string,zap.AtomicLevel. 建议使用string
支持的string为 DEBUG|INFO|WARN|ERROR|DPANIC|PANIC|FATAL

type Option

type Option func(options *Options)

func WithStackWithFmtFormatter

func WithStackWithFmtFormatter(stackWithFmtFormatter bool) Option

WithStackWithFmtFormatter 是否使用 fmt.Formatter 替换zap原本的stacktrace

@param stackWithFmtFormatter
@return Option

type Options

type Options struct {
	StackWithFmtFormatter bool // 是否使用 fmt.Formatter 替换zap原本的stacktrace
}

type ZapCore

type ZapCore struct {
	zapcore.Core
}

ZapCore 自定义zap core,主要实现了替换stacktrace为pkg/errors Wrap后的stacktrace

func (*ZapCore) Check

func (*ZapCore) With

func (h *ZapCore) With(fields []zapcore.Field) zapcore.Core

func (*ZapCore) Write

func (h *ZapCore) Write(ent zapcore.Entry, fields []zapcore.Field) error

Jump to

Keyboard shortcuts

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