A secure log tool fo go
Create logger
seclog.Init(seclog.Config{
LoggerLevel: loggerLevel,
LoggerFile: loggerFile,
LogFormatText: false,
LogColorMode: "auto",
})
logger := seclog.NewLogger(component)
- LoggerLevel: 日志级别由低到高分别为 DEBUG, INFO, WARN, ERROR, FATAL 共5个级别,这里设置的级别是日志输出的最低级别,只有不低于该级别的日志才会输出
- LoggerFile: 输出日志的文件名,为空则输出到 os.Stdout
- LogFormatText: 设定日志的输出格式是 json 还是 plaintext
- LogColorMode: 设定日志的输出是否带颜色,auto: 自动,只有writer是stdout时才带颜色;always:带颜色;never:不带颜色;默认auto
Create logger with multiple sinker
seclog.Init(seclog.Config{
LoggerLevel: "DEBUG",
LoggerFile: "test.log",
LogFormatText: false,
Writers: []string{"file", "stdout"},
LogColorMode: "auto",
})
logger := seclog.NewLogger("example")
Custom your own sinker
type w struct {
}
func (w *w) Write(p []byte) (n int, err error) {
fmt.Print("fake")
return 0, nil
}
func main() {
seclog.RegisterWriter("test", &w{})
}
See Examples
Change log level on-fly
l.SetLogLevel(lager.ERROR)