Merge pull request #333 from heavenlyhash/configurable-logfmt

Add ability to use json structured logging format.
This commit is contained in:
Mrunal Patel 2015-10-14 11:23:10 -07:00
commit 7a95a531ba
1 changed files with 13 additions and 0 deletions

13
main.go
View File

@ -50,6 +50,11 @@ func main() {
Name: "log", Name: "log",
Usage: "set the log file path where internal debug information is written", Usage: "set the log file path where internal debug information is written",
}, },
cli.StringFlag{
Name: "log-format",
Value: "text",
Usage: "set the format used by logs ('text' (default), or 'json')",
},
cli.StringFlag{ cli.StringFlag{
Name: "root", Name: "root",
Value: specs.LinuxStateDirectory, Value: specs.LinuxStateDirectory,
@ -83,6 +88,14 @@ func main() {
} }
logrus.SetOutput(f) logrus.SetOutput(f)
} }
switch context.GlobalString("log-format") {
case "text":
// retain logrus's default.
case "json":
logrus.SetFormatter(new(logrus.JSONFormatter))
default:
logrus.Fatalf("unknown log-format %q", context.GlobalString("log-format"))
}
return nil return nil
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {