Documentation ¶
Index ¶
- Constants
- func Debug(msg string)
- func DebugContext(ctx context.Context, msg string)
- func DebugContextf(ctx context.Context, format string, args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(msg string)
- func ErrorContext(ctx context.Context, msg string)
- func ErrorContextf(ctx context.Context, format string, args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(msg string)
- func FatalContext(ctx context.Context, msg string)
- func FatalContextf(ctx context.Context, format string, args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(msg string)
- func InfoContext(ctx context.Context, msg string)
- func InfoContextf(ctx context.Context, format string, args ...interface{})
- func Infof(format string, args ...interface{})
- func NewDefaultLogger(configs ...*Config) error
- func ToContext(ctx context.Context, logger Logger) context.Context
- func Warn(msg string)
- func WarnContext(ctx context.Context, msg string)
- func WarnContextf(ctx context.Context, format string, args ...interface{})
- func Warnf(format string, args ...interface{})
- type Config
- type Fields
- type Logger
- func FromContext(ctx context.Context) Logger
- func New(configs ...*Config) (Logger, error)
- func NewWithCallerSkip(skip int, configs ...*Config) (Logger, error)
- func WithContextField(ctx context.Context, key string, value interface{}) Logger
- func WithContextFields(ctx context.Context, fields Fields) Logger
- func WithField(key string, value interface{}) Logger
- func WithFields(fields Fields) Logger
- type Writer
Constants ¶
const ( OutputTypeConsole = "console" // 日志输出类型:console OutputTypeFile = "file" // 日志输出类型:文件 )
Variables ¶
This section is empty.
Functions ¶
func DebugContext ¶
DebugContext 打印Debug等级的日志,优先使用ctx中的logger
func DebugContextf ¶
DebugContextf 使用fmt.Sprintf打印Debug等级的日志,优先使用ctx中的logger
func ErrorContext ¶
ErrorContext 打印Error等级的日志,优先使用ctx中的logger
func ErrorContextf ¶
ErrorContextf 使用fmt.Sprintf打印Error等级的日志,优先使用ctx中的logger
func FatalContext ¶
FatalContext 打印Fatal等级的日志,优先使用ctx中的logger
func FatalContextf ¶
FatalContextf 使用fmt.Sprintf打印Fatal等级的日志,优先使用ctx中的logger
func InfoContext ¶
InfoContext 打印Info等级的日志,优先使用ctx中的logger
func InfoContextf ¶
InfoContextf 使用fmt.Sprintf打印Info等级的日志,优先使用ctx中的logger
func NewDefaultLogger ¶
NewDefaultLogger 使用新的配置覆盖默认日志器
func WarnContext ¶
WarnContext 打印Warn等级的日志,优先使用ctx中的logger
func WarnContextf ¶
WarnContextf 使用fmt.Sprintf打印Warn等级的日志,优先使用ctx中的logger
Types ¶
type Config ¶
type Config struct { Type string // 日志类型:console/file Level string // 日志等级:debug/info/warn/error/fatal // 以下配置仅在类型为file时生效,核心逻辑为按照文件大小切割文件 Path string // 文件目录路径 Filename string // 文件名称 MaxSize int64 // 文件最大大小,单位MB MaxAge int64 // 文件最大保存时间,单位天 MaxBackups int64 // 文件最大保存数量 Compress bool // 是否压缩文件 }
Config 日志配置
type Logger ¶
type Logger interface { // Debug 打印Debug等级的日志 Debug(msg string) // Info 打印Info等级的日志 Info(msg string) // Warn 打印Warn等级的日志 Warn(msg string) // Error 打印Error等级的日志 Error(msg string) // Fatal 打印Fatal等级的日志 Fatal(msg string) // Debugf 使用fmt.Sprintf打印Debug等级的日志 Debugf(template string, args ...interface{}) // Infof 使用fmt.Sprintf打印Info等级的日志 Infof(template string, args ...interface{}) // Warnf 使用fmt.Sprintf打印Warn等级的日志 Warnf(template string, args ...interface{}) // Errorf 使用fmt.Sprintf打印Error等级的日志 Errorf(template string, args ...interface{}) // Fatalf 使用fmt.Sprintf打印Fatal等级的日志 Fatalf(template string, args ...interface{}) // WithField 向日志增加一个自定义字段 WithField(key string, value interface{}) Logger // WithFields 向日志增加多个自定义字段 WithFields(fields Fields) Logger }
Logger 日志接口
func NewWithCallerSkip ¶
NewWithCallerSkip 创建新的日志器,额外加上skip调用者的个数
func WithContextField ¶
WithContextField 向ctx中的日志器中增加一个自定义字段,不会修改ctx中的日志器
func WithContextFields ¶
WithContextFields 向ctx中的日志器中增加多个自定义字段,不会修改ctx中的日志器