Skip to content

Commit b5e6125

Browse files
committed
Add config option for JSON log output.
1 parent a9bb4ed commit b5e6125

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

cmd/chirpstack-gateway-bridge/cmd/configfile.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const configTemplate = `[general]
1414
# debug=5, info=4, warning=3, error=2, fatal=1, panic=0
1515
log_level={{ .General.LogLevel }}
1616
17+
# Log in JSON format.
18+
log_json={{ .General.LogJSON }}
19+
1720
# Log to syslog.
1821
#
1922
# When set to true, log messages are being written to syslog.

cmd/chirpstack-gateway-bridge/cmd/root_run.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
func run(cmd *cobra.Command, args []string) error {
2323

2424
tasks := []func() error{
25+
setLogJSON,
2526
setLogLevel,
2627
setSyslog,
2728
printStartMessage,
@@ -52,6 +53,13 @@ func run(cmd *cobra.Command, args []string) error {
5253
return nil
5354
}
5455

56+
func setLogJSON() error {
57+
if config.C.General.LogJSON {
58+
log.SetFormatter(&log.JSONFormatter{})
59+
}
60+
return nil
61+
}
62+
5563
func setLogLevel() error {
5664
log.SetLevel(log.Level(uint8(config.C.General.LogLevel)))
5765
return nil

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
// Config defines the configuration structure.
88
type Config struct {
99
General struct {
10+
LogJSON bool `mapstructure:"log_json"`
1011
LogLevel int `mapstructure:"log_level"`
1112
LogToSyslog bool `mapstructure:"log_to_syslog"`
1213
} `mapstructure:"general"`

0 commit comments

Comments
 (0)