add logtest command
This commit is contained in:
parent
5df8d5f7ae
commit
781204fd87
23
cmd/logtest.go
Normal file
23
cmd/logtest.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(logtestCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var logtestCmd = &cobra.Command{
|
||||||
|
Use: "logtest",
|
||||||
|
Short: "Test logging",
|
||||||
|
Long: "Test logging",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
log.WithField("msg-id", 11987).Trace("This is a trace")
|
||||||
|
log.WithField("bob", "your uncle").Debug("This is debug")
|
||||||
|
log.WithField("userid", "mike").Info("This is an info")
|
||||||
|
log.WithField("jenny", 8675309).Warn("This is a warning")
|
||||||
|
log.WithField("OMG", "Ponies").Error("This is an error")
|
||||||
|
},
|
||||||
|
}
|
||||||
@ -42,7 +42,14 @@ func initConfig() {
|
|||||||
log.SetFormatter(&log.JSONFormatter{})
|
log.SetFormatter(&log.JSONFormatter{})
|
||||||
log.SetOutput(os.Stdout)
|
log.SetOutput(os.Stdout)
|
||||||
} else {
|
} else {
|
||||||
log.SetFormatter(&log.TextFormatter{})
|
log.SetFormatter(&log.JSONFormatter{
|
||||||
|
PrettyPrint: true,
|
||||||
|
FieldMap: log.FieldMap{
|
||||||
|
log.FieldKeyLevel: "priority",
|
||||||
|
log.FieldKeyTime: "timestamp",
|
||||||
|
log.FieldKeyMsg: "message",
|
||||||
|
},
|
||||||
|
DataKey: "opt"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user