first commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.corp.kornet35.ru/gopkg/logrus"
|
||||
"git.corp.kornet35.ru/gopkg/nested"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Print("\n--- logrus-formatter-nested ---\n\n")
|
||||
|
||||
printDemo(&nested.Formatter{
|
||||
HideKeys: true,
|
||||
FieldsOrder: []string{"component", "category", "req"},
|
||||
}, "logrus-formatter-nested")
|
||||
|
||||
fmt.Print("\n--- default logrus formatter ---\n\n")
|
||||
printDemo(nil, "default logrus formatter")
|
||||
}
|
||||
|
||||
func printDemo(f logrus.Formatter, title string) {
|
||||
l := logrus.New()
|
||||
|
||||
l.SetLevel(logrus.DebugLevel)
|
||||
|
||||
if f != nil {
|
||||
l.SetFormatter(f)
|
||||
}
|
||||
|
||||
// enable/disable file/function name
|
||||
l.SetReportCaller(false)
|
||||
|
||||
l.Infof("this is %v demo", title)
|
||||
|
||||
lWebServer := l.WithField("component", "web-server")
|
||||
lWebServer.Info("starting...")
|
||||
|
||||
lWebServerReq := lWebServer.WithFields(logrus.Fields{
|
||||
"req": "GET /api/stats",
|
||||
"reqId": "#1",
|
||||
})
|
||||
|
||||
lWebServerReq.Info("params: startYear=2048")
|
||||
lWebServerReq.Error("response: 400 Bad Request")
|
||||
|
||||
lDbConnector := l.WithField("category", "db-connector")
|
||||
lDbConnector.Info("connecting to db on 10.10.10.13...")
|
||||
lDbConnector.Warn("connection took 10s")
|
||||
|
||||
l.Info("demo end.")
|
||||
}
|
||||
Reference in New Issue
Block a user