easylog
是一个基于 lumberjack 和 zap 封装的的golang日志库, 已在生产环境使用。
import (
"github.com/logerror/easylog"
"github.com/logerror/easylog/pkg/option"
)
easylog.Warn("123")
InitGlobalLogger接收一个可变参数,你可以根据需求配置
log := easylog.InitGlobalLogger(option.WithLogLevel("error"))
defer log.Sync()
easylog.Info("some error to log")
支持配置文件路径,文件大小,是否归档压缩日志文件
log := easylog.InitGlobalLogger(
option.WithLogLevel("info"),
option.WithLogFile("2.log", 1, false),
)
defer log.Sync()
easylog.Info(" some error to log")
logger = easylog.InitGlobalLogger(
option.WithLogLevel("info"),
option.WithLogFile(logFilePath, 5, 0, 0, false),
option.WithConsole(false),
)
easylog.ReplaceLogger(logger)
// AddCallerSkip increases the number of callers skipped by caller annotation
// (as enabled by the AddCaller option). When building wrappers around the
// Logger and SugaredLogger, supplying this Option prevents zap from always
// reporting the wrapper code as the caller.
log := drlog.InitGlobalLogger(option.WithCallerSkip(1))
defer log.Sync()
drlog.Info(" some error to log")