Skip to content

Commit 89e7894

Browse files
committed
added JSON logging flag
1 parent 1b653cb commit 89e7894

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

command/daemon/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414

1515
// Config stores the system configuration.
1616
type Config struct {
17-
Debug bool `envconfig:"DRONE_DEBUG"`
18-
Trace bool `envconfig:"DRONE_TRACE"`
17+
Debug bool `envconfig:"DRONE_DEBUG"`
18+
Trace bool `envconfig:"DRONE_TRACE"`
19+
LogJSON bool `envconfig:"DRONE_LOG_JSON"`
1920

2021
Client struct {
2122
Address string `ignored:"true"`

command/daemon/daemon.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ func setupLogger(config Config) {
275275
if config.Trace {
276276
logrus.SetLevel(logrus.TraceLevel)
277277
}
278-
logrus.SetFormatter(&logrus.JSONFormatter{})
278+
if config.LogJSON {
279+
logrus.SetFormatter(&logrus.JSONFormatter{})
280+
}
279281
}
280282

281283
// Register the daemon command.

command/exec.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type execCommand struct {
5656
Procs int64
5757
Debug bool
5858
Trace bool
59+
LogJSON bool
5960
Dump bool
6061
PublicKey string
6162
PrivateKey string
@@ -224,7 +225,9 @@ func (c *execCommand) run(*kingpin.ParseContext) error {
224225
if c.Trace {
225226
logrus.SetLevel(logrus.TraceLevel)
226227
}
227-
logrus.SetFormatter(&logrus.JSONFormatter{})
228+
if c.LogJSON {
229+
logrus.SetFormatter(&logrus.JSONFormatter{})
230+
}
228231

229232
logger.Default = logger.Logrus(
230233
logrus.NewEntry(
@@ -359,6 +362,9 @@ func registerExec(app *kingpin.Application) {
359362
cmd.Flag("trace", "enable trace logging").
360363
BoolVar(&c.Trace)
361364

365+
cmd.Flag("log-json", "enable JSON structured logging").
366+
BoolVar(&c.LogJSON)
367+
362368
cmd.Flag("dump", "dump the pipeline state to stdout").
363369
BoolVar(&c.Dump)
364370

0 commit comments

Comments
 (0)