Documentation ¶
Overview ¶
Package logger wrapped zap as a basic logging implement.
Index ¶
- Constants
- Variables
- func Close()
- func InitCustomizeRoot(opt *Option) (*zap.Logger, error)
- func InitRoot(opt *Option) error
- func NewLoggerCtx(opts ...CtxOption) *loggerCtx
- func Reset()
- func SetGlobalRootLogger(fpath, level string, options int) error
- func TotalSLoggers() int64
- type CtxOption
- type ExtractTrace
- type Logger
- type LoggerCtx
- type Option
- type Trace
Constants ¶
View Source
const ( // 禁用 JSON 形式输出. OPT_ENC_CONSOLE = 1 //nolint:golint,stylecheck // 显示代码路径时,不显示全路径. OPT_SHORT_CALLER = 2 //nolint:stylecheck,golint // 日志写到 stdout. OPT_STDOUT = 4 //nolint:stylecheck,golint // 日志内容中追加颜色. OPT_COLOR = 8 //nolint:stylecheck,golint // 日志自动切割. OPT_ROTATE = 32 //nolint:stylecheck,golint // 默认日志 flags. OPT_DEFAULT = OPT_ENC_CONSOLE | OPT_SHORT_CALLER | OPT_ROTATE //nolint:stylecheck,golint DEBUG = "debug" INFO = "info" WARN = "warn" ERROR = "error" PANIC = "panic" DPANIC = "dpanic" FATAL = "fatal" )
View Source
const ( NameKeyMod = "mod" NameKeyMsg = "msg" NameKeyLevel = "lev" NameKeyTime = "ts" NameKeyPos = "pos" )
View Source
const (
STDOUT = "stdout" // log output to stdout
)
Variables ¶
View Source
var ( MaxSize = 32 // MB MaxBackups = 5 MaxAge = 30 // day )
View Source
var ( SchemeTCP = "tcp" SchemeUDP = "udp" )
View Source
var ( StdoutColor bool StdoutLevel = DEBUG )
Functions ¶
func InitRoot ¶
InitRoot used to setup global root logger, include
- log level
- log path
- set to disk file(with or without rotate)
- set to some remtoe TCP/UDP server
- a bounch of other OPT_XXXs
func NewLoggerCtx ¶ added in v0.1.6
func NewLoggerCtx(opts ...CtxOption) *loggerCtx
func SetGlobalRootLogger ¶
SetGlobalRootLogger deprecated, use InitRoot() instead.
func TotalSLoggers ¶
func TotalSLoggers() int64
Types ¶
type CtxOption ¶ added in v0.1.6
type CtxOption interface {
// contains filtered or unexported methods
}
func EnableTrace ¶ added in v0.1.6
func EnableTrace() CtxOption
func WithParseTrace ¶ added in v0.1.6
func WithParseTrace(f ExtractTrace) CtxOption
func WithTraceKey ¶ added in v0.1.6
func WithZapCore ¶ added in v0.1.6
func WithZapOpts ¶ added in v0.1.6
type ExtractTrace ¶ added in v0.1.6
type LoggerCtx ¶ added in v0.1.6
type LoggerCtx interface { Debugf(template string, args ...interface{}) Infof(template string, args ...interface{}) Warnf(template string, args ...interface{}) Errorf(template string, args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) DebugfCtx(ctx context.Context, template string, args ...interface{}) InfofCtx(ctx context.Context, template string, args ...interface{}) WarnfCtx(ctx context.Context, template string, args ...interface{}) ErrorfCtx(ctx context.Context, template string, args ...interface{}) DebugCtx(ctx context.Context, template string, args ...interface{}) InfoCtx(ctx context.Context, template string, args ...interface{}) WarnCtx(ctx context.Context, template string, args ...interface{}) ErrorCtx(ctx context.Context, template string, args ...interface{}) Named(name string) LoggerCtx With(fields ...zap.Field) LoggerCtx }
Click to show internal directories.
Click to hide internal directories.