Documentation ¶
Index ¶
- Constants
- func Debug(msg string)
- func DebugContext(ctx context.Context, msg string)
- func DebugContextF(ctx context.Context, format string, v ...interface{})
- func DebugF(format string, v ...interface{})
- func Error(msg string)
- func ErrorContext(ctx context.Context, msg string)
- func ErrorContextF(ctx context.Context, format string, v ...interface{})
- func ErrorF(format string, v ...interface{})
- func Info(msg string)
- func InfoContext(ctx context.Context, msg string)
- func InfoContextF(ctx context.Context, format string, v ...interface{})
- func InfoF(format string, v ...interface{})
- func Warn(msg string)
- func WarnContext(ctx context.Context, msg string)
- func WarnContextF(ctx context.Context, format string, v ...interface{})
- func WarnF(format string, v ...interface{})
- type FileSegmentOptions
- type LoggerHelper
- type NameLog
- func (n *NameLog) Debug(msg string)
- func (n *NameLog) DebugContext(ctx context.Context, msg string)
- func (n *NameLog) DebugContextF(ctx context.Context, format string, v ...interface{})
- func (n *NameLog) DebugF(format string, v ...interface{})
- func (n *NameLog) Error(msg string)
- func (n *NameLog) ErrorContext(ctx context.Context, msg string)
- func (n *NameLog) ErrorContextF(ctx context.Context, format string, v ...interface{})
- func (n *NameLog) ErrorF(format string, v ...interface{})
- func (n *NameLog) Info(msg string)
- func (n *NameLog) InfoContext(ctx context.Context, msg string)
- func (n *NameLog) InfoContextF(ctx context.Context, format string, v ...interface{})
- func (n *NameLog) InfoF(format string, v ...interface{})
- func (n *NameLog) Warn(msg string)
- func (n *NameLog) WarnContext(ctx context.Context, msg string)
- func (n *NameLog) WarnContextF(ctx context.Context, format string, v ...interface{})
- func (n *NameLog) WarnF(format string, v ...interface{})
- type Option
- func WithColor(on bool) Option
- func WithConsoleFormat() Option
- func WithDebugLevel() Option
- func WithFileSegment(on bool) Option
- func WithFileSegmentOption(maxSize, maxAge, maxBackups int) Option
- func WithInfoLevel() Option
- func WithJsonFormat() Option
- func WithOutPutPath(outPutPath, errorOutPutPath []string) Option
- type Options
- type ZapLogger
- func (l *ZapLogger) Debug(msg string)
- func (l *ZapLogger) DebugContext(ctx context.Context, msg string)
- func (l *ZapLogger) DebugContextF(ctx context.Context, format string, v ...interface{})
- func (l *ZapLogger) DebugF(format string, v ...interface{})
- func (l *ZapLogger) Error(msg string)
- func (l *ZapLogger) ErrorContext(ctx context.Context, msg string)
- func (l *ZapLogger) ErrorContextF(ctx context.Context, format string, v ...interface{})
- func (l *ZapLogger) ErrorF(format string, v ...interface{})
- func (l *ZapLogger) Flush()
- func (l *ZapLogger) Info(msg string)
- func (l *ZapLogger) InfoContext(ctx context.Context, msg string)
- func (l *ZapLogger) InfoContextF(ctx context.Context, format string, v ...interface{})
- func (l *ZapLogger) InfoF(format string, v ...interface{})
- func (l *ZapLogger) Warn(msg string)
- func (l *ZapLogger) WarnContext(ctx context.Context, msg string)
- func (l *ZapLogger) WarnContextF(ctx context.Context, format string, v ...interface{})
- func (l *ZapLogger) WarnF(format string, v ...interface{})
- func (l *ZapLogger) WithOptions(opts ...zap.Option) *ZapLogger
- type ZapLoggerOption
Constants ¶
View Source
const ( KeyRequestID string = "requestID" KeyUsername string = "username" KeyUserID string = "userid" )
Variables ¶
This section is empty.
Functions ¶
func DebugContext ¶
func DebugContextF ¶
func ErrorContext ¶
func ErrorContextF ¶
func InfoContext ¶
func InfoContextF ¶
func WarnContext ¶
func WarnContextF ¶
Types ¶
type FileSegmentOptions ¶
type FileSegmentOptions struct { // MaxSize 进行切割之前,日志文件的最大大小(MB为单位),默认为100MB MaxSize int `json:"max-size" mapstructure:"max-size"` // MaxAge 是根据文件名中编码的时间戳保留旧日志文件的最大天数,默认为30天。 MaxAge int `json:"max-age" mapstructure:"max-age"` // MaxBackups 是要保留的旧日志文件的最大数量。默认是保留所有旧的日志文件(尽管 MaxAge 可能仍会导致它们被删除。) MaxBackups int `json:"max-backups" mapstructure:"max-backups"` }
type LoggerHelper ¶
type LoggerHelper interface { Debug(msg string) DebugF(format string, v ...interface{}) DebugContext(ctx context.Context, msg string) DebugContextF(ctx context.Context, format string, v ...interface{}) Info(msg string) InfoF(format string, v ...interface{}) InfoContext(ctx context.Context, msg string) InfoContextF(ctx context.Context, format string, v ...interface{}) Warn(msg string) WarnF(format string, v ...interface{}) WarnContext(ctx context.Context, msg string) WarnContextF(ctx context.Context, format string, v ...interface{}) Error(msg string) ErrorF(format string, v ...interface{}) ErrorContext(ctx context.Context, msg string) ErrorContextF(ctx context.Context, format string, v ...interface{}) }
LoggerHelper 打印日志的顶层接口,有Context传入的参数,会根据配置将日志发送到远程分析程序
func GetLogger ¶
func GetLogger() LoggerHelper
func Init ¶
func Init(opts *Options, zapOptions ...ZapLoggerOption) LoggerHelper
type NameLog ¶
type NameLog struct {
// contains filtered or unexported fields
}
func NewNameLog ¶
func NewNameLog(log LoggerHelper, name string) *NameLog
func (*NameLog) DebugContextF ¶
func (*NameLog) ErrorContextF ¶
func (*NameLog) InfoContextF ¶
func (*NameLog) WarnContextF ¶
type Option ¶
type Option func(*Options)
func WithConsoleFormat ¶
func WithConsoleFormat() Option
func WithDebugLevel ¶
func WithDebugLevel() Option
func WithFileSegment ¶
func WithFileSegmentOption ¶
func WithInfoLevel ¶
func WithInfoLevel() Option
func WithJsonFormat ¶
func WithJsonFormat() Option
func WithOutPutPath ¶
type Options ¶
type Options struct { // 日志级别,选项(debug,info,warn,error,dpanic,panic,fatal) Level string `json:"level" mapstructure:"level"` // json的格式,选项(console,json) Format string `json:"format" mapstructure:"format"` // 停止使用调用函数的文件名和行号注释日志, 在默认情况下 所有日志都有注释 DisableCaller bool `json:"disable-caller" mapstructure:"disable-caller"` // 禁用自动捕获堆栈跟踪。默认情况下,在 dev 环境中捕获WarnLevel及以上级别的日志,在 pro 环境中捕获ErrorLevel及以上级别的日志 DisableStacktrace bool `json:"disable-stacktrace" mapstructure:"disable-stacktrace"` EnableColor bool `json:"enable-color" mapstructure:"enable-color"` // 是否是开发模式 Development bool `json:"development" mapstructure:"development"` // 日志名称 Name string `json:"name" mapstructure:"name"` //是否开启traceID EnableTraceID bool `json:"enable-trace-id" mapstructure:"enable-trace-id"` //是否开启traceStack EnableTraceStack bool `json:"enable-trace-stack" mapstructure:"enable-trace-stack"` // 输出 默认输出到标准输出,如果不是标准输出,则认为是文件输出 OutputPaths []string `json:"output-paths" mapstructure:"output-paths"` // 错误输出 默认输出到标准错误 ErrorOutputPaths []string `json:"error-output-paths" mapstructure:"error-output-paths"` //是否开启文件分割,默认不分割 EnableFileSegment bool `json:"enable-file-segment" mapstructure:"enable-file-segment"` // 文件分割策略 FileSegment FileSegmentOptions `json:"file-segment" mapstructure:"file-segment"` }
Options 日志的配置类,推荐使用NewOptions方法创建默认的配置,然后再根据配置文件进行填充个性化配置
func NewOptions ¶
type ZapLogger ¶
ZapLogger log的zap实现类,推荐调用NewZapLog方法创建
func NewZapLog ¶
func NewZapLog(opts *Options, zapOptions ...ZapLoggerOption) *ZapLogger
func (*ZapLogger) DebugContextF ¶
func (*ZapLogger) ErrorContextF ¶
func (*ZapLogger) InfoContextF ¶
func (*ZapLogger) WarnContextF ¶
type ZapLoggerOption ¶
type ZapLoggerOption func(*ZapLogger)
func WithCaller ¶
func WithCaller(on bool) ZapLoggerOption
func WithStackTrace ¶
func WithStackTrace(on bool) ZapLoggerOption
func WithSugar ¶
func WithSugar(on bool) ZapLoggerOption
Click to show internal directories.
Click to hide internal directories.