日志记录
原文:https://gobuffalo.io/documentation/guides/logging/
Logging 日志记录
Buffalo logs are managed using the logrus package.
Buffalo 日志使用 logrus 包进行管理。
Defaults 默认值
The default logger outputs logs in a human-readable format:
默认记录器以人类可读的格式输出日志:
1
| INFO[2020-02-21T07:42:34+01:00] /en/ content_type=text/html duration=26.189949ms human_size="21 kB" method=GET params="{\"lang\":[\"en\"]}" path=/en/ render=22.730816ms request_id=9b8d9260225fe99609a2-7cc679f4ae458b9925e3 size=21182 status=200
|
Customize the logger 自定义记录器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| // JSONLogger wraps a logrus JSON logger into a buffalo Logger
func JSONLogger(lvl logger.Level) logger.FieldLogger {
l := logrus.New()
l.Level = lvl
l.SetFormatter(&logrus.JSONFormatter{})
l.SetOutput(os.Stdout)
return logger.Logrus{FieldLogger: l}
}
//...
app = buffalo.New(buffalo.Options{
// ...
Logger: JSONLogger(logger.DebugLevel),
}
|