diff --git a/command/daemon/config.go b/command/daemon/config.go index ac7012e..63cf577 100644 --- a/command/daemon/config.go +++ b/command/daemon/config.go @@ -14,8 +14,9 @@ import ( // Config stores the system configuration. type Config struct { - Debug bool `envconfig:"DRONE_DEBUG"` - Trace bool `envconfig:"DRONE_TRACE"` + Debug bool `envconfig:"DRONE_DEBUG"` + Trace bool `envconfig:"DRONE_TRACE"` + LogJSON bool `envconfig:"DRONE_LOG_JSON"` Client struct { Address string `ignored:"true"` diff --git a/command/daemon/daemon.go b/command/daemon/daemon.go index 015f3d2..2aaeb71 100644 --- a/command/daemon/daemon.go +++ b/command/daemon/daemon.go @@ -275,6 +275,9 @@ func setupLogger(config Config) { if config.Trace { logrus.SetLevel(logrus.TraceLevel) } + if config.LogJSON { + logrus.SetFormatter(&logrus.JSONFormatter{}) + } } // Register the daemon command. diff --git a/command/exec.go b/command/exec.go index c623002..1f99265 100644 --- a/command/exec.go +++ b/command/exec.go @@ -56,6 +56,7 @@ type execCommand struct { Procs int64 Debug bool Trace bool + LogJSON bool Dump bool PublicKey string PrivateKey string @@ -224,6 +225,10 @@ func (c *execCommand) run(*kingpin.ParseContext) error { if c.Trace { logrus.SetLevel(logrus.TraceLevel) } + if c.LogJSON { + logrus.SetFormatter(&logrus.JSONFormatter{}) + } + logger.Default = logger.Logrus( logrus.NewEntry( logrus.StandardLogger(), @@ -357,6 +362,9 @@ func registerExec(app *kingpin.Application) { cmd.Flag("trace", "enable trace logging"). BoolVar(&c.Trace) + cmd.Flag("log-json", "enable JSON structured logging"). + BoolVar(&c.LogJSON) + cmd.Flag("dump", "dump the pipeline state to stdout"). BoolVar(&c.Dump)