diff --git a/cmd/logtest.go b/cmd/logtest.go new file mode 100644 index 0000000..ee8a123 --- /dev/null +++ b/cmd/logtest.go @@ -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") + }, +} diff --git a/cmd/root.go b/cmd/root.go index 1f29146..373ae47 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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"}) } }