diff --git a/cmd/chirpstack-gateway-bridge/cmd/configfile.go b/cmd/chirpstack-gateway-bridge/cmd/configfile.go index 514dd9b6..94d85a98 100644 --- a/cmd/chirpstack-gateway-bridge/cmd/configfile.go +++ b/cmd/chirpstack-gateway-bridge/cmd/configfile.go @@ -14,6 +14,9 @@ const configTemplate = `[general] # debug=5, info=4, warning=3, error=2, fatal=1, panic=0 log_level={{ .General.LogLevel }} +# Log in JSON format. +log_json={{ .General.LogJSON }} + # Log to syslog. # # When set to true, log messages are being written to syslog. diff --git a/cmd/chirpstack-gateway-bridge/cmd/root_run.go b/cmd/chirpstack-gateway-bridge/cmd/root_run.go index f3de7e2d..eb784338 100644 --- a/cmd/chirpstack-gateway-bridge/cmd/root_run.go +++ b/cmd/chirpstack-gateway-bridge/cmd/root_run.go @@ -22,6 +22,7 @@ import ( func run(cmd *cobra.Command, args []string) error { tasks := []func() error{ + setLogJSON, setLogLevel, setSyslog, printStartMessage, @@ -52,6 +53,13 @@ func run(cmd *cobra.Command, args []string) error { return nil } +func setLogJSON() error { + if config.C.General.LogJSON { + log.SetFormatter(&log.JSONFormatter{}) + } + return nil +} + func setLogLevel() error { log.SetLevel(log.Level(uint8(config.C.General.LogLevel))) return nil diff --git a/internal/config/config.go b/internal/config/config.go index f7baa181..70d42f2a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,6 +7,7 @@ import ( // Config defines the configuration structure. type Config struct { General struct { + LogJSON bool `mapstructure:"log_json"` LogLevel int `mapstructure:"log_level"` LogToSyslog bool `mapstructure:"log_to_syslog"` } `mapstructure:"general"`