log

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 11 Imported by: 15

Documentation

Index

Constants

View Source
const (
	LOGGER_ERR_TYPE      = "err"
	LOGGER_ACCESS_TYPE   = "access"
	LOGGER_BUSINESS_TYPE = "business"

	FLAG_SERVICE_NAME = ":service_name"
	FLAG_LOGGER_TYPE  = ":logger_type"
	FLAG_EMPTY        = "/:-"
)
View Source
const (
	LEVEL_DEBUG = uint8(iota)
	LEVEL_INFO
	LEVEL_WARN
	LEVEL_ERROR

	ZEROLOG_CALLER_SKIP = 3
	LOG_CALLER_SKIP     = 4
)

Variables

This section is empty.

Functions

func InitGlobalConfig

func InitGlobalConfig(rootPath string, level string, appName string) error

Types

type EmptyLoggerContext

type EmptyLoggerContext struct {
}

func (*EmptyLoggerContext) Debug

func (e *EmptyLoggerContext) Debug(ctx context.Context, msg ...interface{})

func (*EmptyLoggerContext) Debugf

func (e *EmptyLoggerContext) Debugf(ctx context.Context, format string, args ...interface{})

func (*EmptyLoggerContext) Error

func (e *EmptyLoggerContext) Error(ctx context.Context, msg ...interface{})

func (*EmptyLoggerContext) Errorf

func (e *EmptyLoggerContext) Errorf(ctx context.Context, format string, args ...interface{})

func (*EmptyLoggerContext) GetDebugLog

func (e *EmptyLoggerContext) GetDebugLog() *zerolog.Event

func (*EmptyLoggerContext) GetErrorLog

func (e *EmptyLoggerContext) GetErrorLog() *zerolog.Event

func (*EmptyLoggerContext) GetInfoLog

func (e *EmptyLoggerContext) GetInfoLog() *zerolog.Event

func (*EmptyLoggerContext) GetLoggerConf

func (e *EmptyLoggerContext) GetLoggerConf() LoggerConf

func (*EmptyLoggerContext) GetWarnLog

func (e *EmptyLoggerContext) GetWarnLog() *zerolog.Event

func (*EmptyLoggerContext) Info

func (e *EmptyLoggerContext) Info(ctx context.Context, msg ...interface{})

func (*EmptyLoggerContext) Infof

func (e *EmptyLoggerContext) Infof(ctx context.Context, format string, args ...interface{})

func (*EmptyLoggerContext) RequestId

func (*EmptyLoggerContext) RequestId(requestId string) LoggerContextIface

func (*EmptyLoggerContext) Tag

func (*EmptyLoggerContext) Warn

func (e *EmptyLoggerContext) Warn(ctx context.Context, msg ...interface{})

func (*EmptyLoggerContext) Warnf

func (e *EmptyLoggerContext) Warnf(ctx context.Context, format string, args ...interface{})

func (*EmptyLoggerContext) WithCaller

func (*EmptyLoggerContext) WithCaller(skip int) LoggerContextIface

func (*EmptyLoggerContext) WithCommonFields

func (*EmptyLoggerContext) WithCommonFields(fields Fields) LoggerContextIface

func (*EmptyLoggerContext) WithContext

func (*EmptyLoggerContext) WithFields

func (*EmptyLoggerContext) WithFields(fields Fields) LoggerContextIface

func (*EmptyLoggerContext) WithLogData

func (*EmptyLoggerContext) WithLogData(logData *LogData) LoggerContextIface

type Fields

type Fields = map[string]interface{}

type LogData

type LogData struct {
	RequestId string                 // 请求id
	TraceId   string                 // 跟踪id
	Attach    map[string]interface{} // 其他附加日志内容
}

type LoggerConf

type LoggerConf struct {
	LogFilePath string // Log文件全路径
	AppName     string
	Level       uint8
	Caller      bool // 是否需要显示Caller,默认false时不显示(注:获取caller会影响性能)
	HideTime    bool // 是否隐藏时间,默认显示
	ContextCall func(l *LoggerContext, ctx context.Context) LoggerContextIface
}

type LoggerContext

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

func GetAccessLogger

func GetAccessLogger(loggerTag string) (*LoggerContext, error)

func GetBusinessLogger

func GetBusinessLogger(loggerTag string) (*LoggerContext, error)

func GetCustomLogger

func GetCustomLogger(customTag, loggerTag string) (*LoggerContext, error)

func GetErrLogger

func GetErrLogger(loggerTag string) (*LoggerContext, error)

func (*LoggerContext) Debug

func (l *LoggerContext) Debug(ctx context.Context, args ...interface{})

func (*LoggerContext) Debugf

func (l *LoggerContext) Debugf(ctx context.Context, format string, args ...interface{})

func (*LoggerContext) Error

func (l *LoggerContext) Error(ctx context.Context, args ...interface{})

func (*LoggerContext) Errorf

func (l *LoggerContext) Errorf(ctx context.Context, format string, args ...interface{})

func (*LoggerContext) GetDebugLog

func (l *LoggerContext) GetDebugLog() *zerolog.Event

func (*LoggerContext) GetErrorLog

func (l *LoggerContext) GetErrorLog() *zerolog.Event

func (*LoggerContext) GetInfoLog

func (l *LoggerContext) GetInfoLog() *zerolog.Event

func (*LoggerContext) GetLoggerConf

func (l *LoggerContext) GetLoggerConf() LoggerConf

func (*LoggerContext) GetWarnLog

func (l *LoggerContext) GetWarnLog() *zerolog.Event

func (*LoggerContext) Info

func (l *LoggerContext) Info(ctx context.Context, args ...interface{})

func (*LoggerContext) Infof

func (l *LoggerContext) Infof(ctx context.Context, format string, args ...interface{})

func (*LoggerContext) RequestId

func (l *LoggerContext) RequestId(requestId string) LoggerContextIface

func (*LoggerContext) Tag

func (*LoggerContext) Warn

func (l *LoggerContext) Warn(ctx context.Context, args ...interface{})

func (*LoggerContext) Warnf

func (l *LoggerContext) Warnf(ctx context.Context, format string, args ...interface{})

func (*LoggerContext) WithCaller

func (l *LoggerContext) WithCaller(skip int) LoggerContextIface

func (*LoggerContext) WithCommonFields

func (l *LoggerContext) WithCommonFields(commonFields Fields) LoggerContextIface

用于全局设置logger对象的公共输出字段 例如:logger = logger.WithCommonFields(logger.Fields{"app-name":"project" }) {"level":"info",app-name":"project", "attach":{"process-id":25921,"speed":"33.771µs"},"msg":"for test"}

func (*LoggerContext) WithContext

func (l *LoggerContext) WithContext(ctx context.Context) LoggerContextIface

func (*LoggerContext) WithFields

func (l *LoggerContext) WithFields(fields Fields) LoggerContextIface

用于输出自定义字段,同时又不影响整体的日志格式(将fields中指定的字段及值附加到attach中) {"level":"info","attach":{"process-id":25921,"speed":"33.771µs"},"msg":"for test"}

func (*LoggerContext) WithLogData

func (l *LoggerContext) WithLogData(logData *LogData) LoggerContextIface

此函数为了兼容老的日志

type LoggerContextIface

type LoggerContextIface interface {
	WithLogData(logData *LogData) LoggerContextIface
	WithCommonFields(commonFields Fields) LoggerContextIface
	WithFields(fields Fields) LoggerContextIface
	WithContext(ctx context.Context) LoggerContextIface
	Tag(tag string) LoggerContextIface
	RequestId(requestId string) LoggerContextIface
	WithCaller(skip int) LoggerContextIface

	Debug(ctx context.Context, args ...interface{})
	Debugf(ctx context.Context, format string, args ...interface{})
	Info(ctx context.Context, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warn(ctx context.Context, args ...interface{})
	Warnf(ctx context.Context, format string, args ...interface{})
	Error(ctx context.Context, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})

	GetDebugLog() *zerolog.Event
	GetInfoLog() *zerolog.Event
	GetWarnLog() *zerolog.Event
	GetErrorLog() *zerolog.Event

	GetLoggerConf() LoggerConf
}

func CreateLogger

func CreateLogger(logConf LoggerConf) (LoggerContextIface, error)

创建日志对象

Jump to

Keyboard shortcuts

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