From 1b653cb888ff46282bcaf5fc18be60e42cd6d6a5 Mon Sep 17 00:00:00 2001 From: prune Date: Tue, 6 Oct 2020 11:25:01 -0400 Subject: [PATCH 1/2] force logs as json --- command/daemon/daemon.go | 1 + command/exec.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/command/daemon/daemon.go b/command/daemon/daemon.go index 015f3d2..547ecdf 100644 --- a/command/daemon/daemon.go +++ b/command/daemon/daemon.go @@ -275,6 +275,7 @@ func setupLogger(config Config) { if config.Trace { logrus.SetLevel(logrus.TraceLevel) } + logrus.SetFormatter(&logrus.JSONFormatter{}) } // Register the daemon command. diff --git a/command/exec.go b/command/exec.go index c623002..e2c3e8f 100644 --- a/command/exec.go +++ b/command/exec.go @@ -224,6 +224,8 @@ func (c *execCommand) run(*kingpin.ParseContext) error { if c.Trace { logrus.SetLevel(logrus.TraceLevel) } + logrus.SetFormatter(&logrus.JSONFormatter{}) + logger.Default = logger.Logrus( logrus.NewEntry( logrus.StandardLogger(), From 89e789425d7e609581d0ec66eeadadb918bb4fd5 Mon Sep 17 00:00:00 2001 From: prune Date: Tue, 20 Jul 2021 16:39:46 -0400 Subject: [PATCH 2/2] added JSON logging flag --- command/daemon/config.go | 5 +++-- command/daemon/daemon.go | 4 +++- command/exec.go | 8 +++++++- 3 files changed, 13 insertions(+), 4 deletions(-) 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 547ecdf..2aaeb71 100644 --- a/command/daemon/daemon.go +++ b/command/daemon/daemon.go @@ -275,7 +275,9 @@ func setupLogger(config Config) { if config.Trace { logrus.SetLevel(logrus.TraceLevel) } - logrus.SetFormatter(&logrus.JSONFormatter{}) + if config.LogJSON { + logrus.SetFormatter(&logrus.JSONFormatter{}) + } } // Register the daemon command. diff --git a/command/exec.go b/command/exec.go index e2c3e8f..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,7 +225,9 @@ func (c *execCommand) run(*kingpin.ParseContext) error { if c.Trace { logrus.SetLevel(logrus.TraceLevel) } - logrus.SetFormatter(&logrus.JSONFormatter{}) + if c.LogJSON { + logrus.SetFormatter(&logrus.JSONFormatter{}) + } logger.Default = logger.Logrus( logrus.NewEntry( @@ -359,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)