From f28e8deb96b454745b9777a33b781e716a90f245 Mon Sep 17 00:00:00 2001 From: Daniele Rondina Date: Fri, 3 Jan 2020 15:20:42 +0100 Subject: [PATCH] logger: Add support for json format --- contrib/config/luet.yaml | 3 +++ pkg/config/config.go | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/contrib/config/luet.yaml b/contrib/config/luet.yaml index 591ea85a..644be0bd 100644 --- a/contrib/config/luet.yaml +++ b/contrib/config/luet.yaml @@ -10,6 +10,9 @@ # Set logging level: error|warning|info|debug # level: "info" # +# Enable JSON log format instead of console mode. +# json_format: false. +# # --------------------------------------------- # General configuration section: # --------------------------------------------- diff --git a/pkg/config/config.go b/pkg/config/config.go index dd5787d1..b5f2ab60 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -27,8 +27,9 @@ import ( var LuetCfg = NewLuetConfig(v.GetViper()) type LuetLoggingConfig struct { - Path string `mapstructure:"path"` - Level string `mapstructure:"level"` + Path string `mapstructure:"path"` + JsonFormat bool `mapstructure:"json_format"` + Level string `mapstructure:"level"` } type LuetGeneralConfig struct { @@ -101,6 +102,7 @@ func GenDefault(viper *v.Viper) { viper.SetDefault("logging.level", "info") viper.SetDefault("logging.path", "") + viper.SetDefault("logging.json_format", false) viper.SetDefault("general.concurrency", runtime.NumCPU()) viper.SetDefault("general.debug", false) @@ -158,7 +160,8 @@ func (c *LuetLoggingConfig) String() string { ans := fmt.Sprintf(` logging: path: %s - level: %s`, c.Path, c.Level) + json_format: %t + level: %s`, c.Path, c.JsonFormat, c.Level) return ans }