logger

package
v0.0.0-...-4abcb88 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

func DebugWithContext

func DebugWithContext(context *context.Context, v ...interface{})

func Debugf

func Debugf(template string, v ...interface{})

func DebugfWithContext

func DebugfWithContext(context *context.Context, template string, v ...interface{})

func Error

func Error(v ...interface{})

func ErrorWithContext

func ErrorWithContext(context *context.Context, v ...interface{})

func Errorf

func Errorf(template string, v ...interface{})

func ErrorfWithContext

func ErrorfWithContext(context *context.Context, template string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func FatalWithContext

func FatalWithContext(context *context.Context, v ...interface{})

func Fatalf

func Fatalf(template string, v ...interface{})

func FatalfWithContext

func FatalfWithContext(context *context.Context, template string, v ...interface{})

func Flush

func Flush()

func Info

func Info(v ...interface{})

func InfoWithContext

func InfoWithContext(context *context.Context, v ...interface{})

func Infof

func Infof(template string, v ...interface{})

func InfofWithContext

func InfofWithContext(context *context.Context, template string, v ...interface{})

func InitLogger

func InitLogger(properties *Properties)

func IsDebugEnabled

func IsDebugEnabled() bool

func IsErrorEnabled

func IsErrorEnabled() bool

func IsFatalEnabled

func IsFatalEnabled() bool

func IsInfoEnabled

func IsInfoEnabled() bool

func IsWarnEnabled

func IsWarnEnabled() bool

func ResolveAndApplyDefaultProperties

func ResolveAndApplyDefaultProperties(properties *Properties)

* 处理默认配置信息

func SetAfterLogHandler

func SetAfterLogHandler(handler func(ctx *context.Context, logText string, level Level))

func SetRootLogger

func SetRootLogger(logger Logger)

func SetTraceIdGenerator

func SetTraceIdGenerator(generator TraceIdGenerator)

func Warn

func Warn(v ...interface{})

func WarnWithContext

func WarnWithContext(context *context.Context, v ...interface{})

func Warnf

func Warnf(template string, v ...interface{})

func WarnfWithContext

func WarnfWithContext(context *context.Context, template string, v ...interface{})

Types

type ConsoleLogger

type ConsoleLogger struct {
	Level            Level // 日志级别
	CallerSkipOffset int   // 输出日志时候,计算输入日志的日志所在文件和行数偏移,一般给应用进行二次封装使用,正负数都可以
}

func (*ConsoleLogger) Debug

func (c *ConsoleLogger) Debug(v ...interface{})

func (*ConsoleLogger) DebugWithContext

func (c *ConsoleLogger) DebugWithContext(context *context.Context, v ...interface{})

func (*ConsoleLogger) Debugf

func (c *ConsoleLogger) Debugf(template string, v ...interface{})

func (*ConsoleLogger) DebugfWithContext

func (c *ConsoleLogger) DebugfWithContext(context *context.Context, template string, v ...interface{})

func (*ConsoleLogger) Error

func (c *ConsoleLogger) Error(v ...interface{})

func (*ConsoleLogger) ErrorWithContext

func (c *ConsoleLogger) ErrorWithContext(context *context.Context, v ...interface{})

func (*ConsoleLogger) Errorf

func (c *ConsoleLogger) Errorf(template string, v ...interface{})

func (*ConsoleLogger) ErrorfWithContext

func (c *ConsoleLogger) ErrorfWithContext(context *context.Context, template string, v ...interface{})

func (*ConsoleLogger) Fatal

func (c *ConsoleLogger) Fatal(v ...interface{})

func (*ConsoleLogger) FatalWithContext

func (c *ConsoleLogger) FatalWithContext(context *context.Context, v ...interface{})

func (*ConsoleLogger) Fatalf

func (c *ConsoleLogger) Fatalf(template string, v ...interface{})

func (*ConsoleLogger) FatalfWithContext

func (c *ConsoleLogger) FatalfWithContext(context *context.Context, template string, v ...interface{})

func (*ConsoleLogger) Flush

func (c *ConsoleLogger) Flush()

func (*ConsoleLogger) GetLevel

func (c *ConsoleLogger) GetLevel() Level

func (*ConsoleLogger) Info

func (c *ConsoleLogger) Info(v ...interface{})

func (*ConsoleLogger) InfoWithContext

func (c *ConsoleLogger) InfoWithContext(context *context.Context, v ...interface{})

func (*ConsoleLogger) Infof

func (c *ConsoleLogger) Infof(template string, v ...interface{})

func (*ConsoleLogger) InfofWithContext

func (c *ConsoleLogger) InfofWithContext(context *context.Context, template string, v ...interface{})

func (*ConsoleLogger) IsDebugEnabled

func (c *ConsoleLogger) IsDebugEnabled() bool

func (*ConsoleLogger) IsErrorEnabled

func (c *ConsoleLogger) IsErrorEnabled() bool

func (*ConsoleLogger) IsFatalEnabled

func (c *ConsoleLogger) IsFatalEnabled() bool

func (*ConsoleLogger) IsInfoEnabled

func (c *ConsoleLogger) IsInfoEnabled() bool

func (*ConsoleLogger) IsWarnEnabled

func (c *ConsoleLogger) IsWarnEnabled() bool

func (*ConsoleLogger) Warn

func (c *ConsoleLogger) Warn(v ...interface{})

func (*ConsoleLogger) WarnWithContext

func (c *ConsoleLogger) WarnWithContext(context *context.Context, v ...interface{})

func (*ConsoleLogger) Warnf

func (c *ConsoleLogger) Warnf(template string, v ...interface{})

func (*ConsoleLogger) WarnfWithContext

func (c *ConsoleLogger) WarnfWithContext(context *context.Context, template string, v ...interface{})

type Level

type Level int8
const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

func GetLevel

func GetLevel() Level

func ParseLevel

func ParseLevel(level string) Level

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Flush()
	GetLevel() Level
	IsDebugEnabled() bool
	IsInfoEnabled() bool
	IsWarnEnabled() bool
	IsErrorEnabled() bool
	IsFatalEnabled() bool

	Debug(v ...interface{})
	Debugf(template string, v ...interface{})
	DebugWithContext(context *context.Context, v ...interface{})
	DebugfWithContext(context *context.Context, template string, v ...interface{})

	Info(v ...interface{})
	Infof(template string, v ...interface{})
	InfoWithContext(context *context.Context, v ...interface{})
	InfofWithContext(context *context.Context, template string, v ...interface{})

	Warn(v ...interface{})
	Warnf(template string, v ...interface{})
	WarnWithContext(context *context.Context, v ...interface{})
	WarnfWithContext(context *context.Context, template string, v ...interface{})

	Error(v ...interface{})
	Errorf(template string, v ...interface{})
	ErrorWithContext(context *context.Context, v ...interface{})
	ErrorfWithContext(context *context.Context, template string, v ...interface{})

	Fatal(v ...interface{})
	Fatalf(template string, v ...interface{})
	FatalWithContext(context *context.Context, v ...interface{})
	FatalfWithContext(context *context.Context, template string, v ...interface{})
}

日志初始化

func RootLogger

func RootLogger() *Logger

type Properties

type Properties struct {
	Level            string `ck:"level" def:"DEBUG"`                         // 日志级别: DEBUG, INFO, WARN, ERROR, FATAL, 默认是: DEBUG
	Dir              string `ck:"dir" def:"./logs"`                          // 日志存放目录, 默认是 ./logs
	Filename         string `ck:"filename" def:"app.log"`                    // 文件名,含后缀, 默认:app.log
	TimeFormat       string `ck:"time-format" def:"2006-01-02 15:04:05.000"` // 时间格式,默认是 2006-01-02 15:04:05.000
	MaxSize          int    `ck:"max-size" def:"500"`                        // 单个配置文件大小最大限制,单位:M,默认是 500 M
	MaxBackups       int    `ck:"max-backups" def:"30"`                      // 最多保留多少个日志文件,默认 30
	MaxAge           int    `ck:"max-age" def:"30"`                          // 日志文件存活时间,单位:天,默认是30天
	Compress         bool   `ck:"compress" def:"false"`                      // 是否需要自动gzip进行压缩,默认:false
	ConsoleLog       bool   `ck:"console-log" def:"false"`                   // 是否需要输出控制台日志,默认是 false
	CallerSkipOffset int    `ck:"caller-skip-offset" def:"0"`                // 输出日志时候,计算输入日志的日志所在文件和行数偏移,一般给应用进行二次封装使用,正负数都可以
}

* 日志配置

func (*Properties) Equals

func (p *Properties) Equals(properties *Properties) bool

type TraceIdGenerator

type TraceIdGenerator func(ctx *context.Context) string

* TraceId 生成器, 允许用户自定义

type ZapLogger

type ZapLogger struct {
	Level Level // 日志级别
	// contains filtered or unexported fields
}

func (*ZapLogger) Debug

func (z *ZapLogger) Debug(v ...interface{})

func (*ZapLogger) DebugWithContext

func (z *ZapLogger) DebugWithContext(context *context.Context, v ...interface{})

func (*ZapLogger) Debugf

func (z *ZapLogger) Debugf(template string, v ...interface{})

func (*ZapLogger) DebugfWithContext

func (z *ZapLogger) DebugfWithContext(context *context.Context, template string, v ...interface{})

func (*ZapLogger) Error

func (z *ZapLogger) Error(v ...interface{})

func (*ZapLogger) ErrorWithContext

func (z *ZapLogger) ErrorWithContext(context *context.Context, v ...interface{})

func (*ZapLogger) Errorf

func (z *ZapLogger) Errorf(template string, v ...interface{})

func (*ZapLogger) ErrorfWithContext

func (z *ZapLogger) ErrorfWithContext(context *context.Context, template string, v ...interface{})

func (*ZapLogger) Fatal

func (z *ZapLogger) Fatal(v ...interface{})

func (*ZapLogger) FatalWithContext

func (z *ZapLogger) FatalWithContext(context *context.Context, v ...interface{})

func (*ZapLogger) Fatalf

func (z *ZapLogger) Fatalf(template string, v ...interface{})

func (*ZapLogger) FatalfWithContext

func (z *ZapLogger) FatalfWithContext(context *context.Context, template string, v ...interface{})

func (*ZapLogger) Flush

func (z *ZapLogger) Flush()

func (*ZapLogger) GetLevel

func (z *ZapLogger) GetLevel() Level

func (*ZapLogger) Info

func (z *ZapLogger) Info(v ...interface{})

func (*ZapLogger) InfoWithContext

func (z *ZapLogger) InfoWithContext(context *context.Context, v ...interface{})

func (*ZapLogger) Infof

func (z *ZapLogger) Infof(template string, v ...interface{})

func (*ZapLogger) InfofWithContext

func (z *ZapLogger) InfofWithContext(context *context.Context, template string, v ...interface{})

func (*ZapLogger) IsDebugEnabled

func (z *ZapLogger) IsDebugEnabled() bool

func (*ZapLogger) IsErrorEnabled

func (z *ZapLogger) IsErrorEnabled() bool

func (*ZapLogger) IsFatalEnabled

func (z *ZapLogger) IsFatalEnabled() bool

func (*ZapLogger) IsInfoEnabled

func (z *ZapLogger) IsInfoEnabled() bool

func (*ZapLogger) IsWarnEnabled

func (z *ZapLogger) IsWarnEnabled() bool

func (*ZapLogger) Warn

func (z *ZapLogger) Warn(v ...interface{})

func (*ZapLogger) WarnWithContext

func (z *ZapLogger) WarnWithContext(context *context.Context, v ...interface{})

func (*ZapLogger) Warnf

func (z *ZapLogger) Warnf(template string, v ...interface{})

func (*ZapLogger) WarnfWithContext

func (z *ZapLogger) WarnfWithContext(context *context.Context, template string, v ...interface{})

Jump to

Keyboard shortcuts

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