From 2add2bc41a6aaa75ec489cbf19dbc4ff6ba77c6f Mon Sep 17 00:00:00 2001 From: Eric Myhre Date: Tue, 13 Oct 2015 18:03:21 -0500 Subject: [PATCH] Add ability to use json structured logging format. Signed-off-by: Eric Myhre --- main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.go b/main.go index 0c12a356..ac011f61 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,11 @@ func main() { Name: "log", 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{ Name: "root", Value: specs.LinuxStateDirectory, @@ -83,6 +88,14 @@ func main() { } 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 } if err := app.Run(os.Args); err != nil {