logger: Add support for json format

This commit is contained in:
Daniele Rondina
2020-01-03 15:20:42 +01:00
parent 4433fc72ac
commit f28e8deb96
2 changed files with 9 additions and 3 deletions

View File

@@ -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:
# ---------------------------------------------

View File

@@ -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
}