add logtest command

This commit is contained in:
Mike Bloy 2019-09-24 22:23:20 -05:00
parent 5df8d5f7ae
commit 781204fd87
2 changed files with 31 additions and 1 deletions

23
cmd/logtest.go Normal file
View 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")
},
}

View File

@ -42,7 +42,14 @@ func initConfig() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
} 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"})
}
}