lib/logger: follow-up for 72f8fce107

- Document the change at docs/CHANELOG.md
- Log fatal errors if the -loggerJSONFields contains unexpected values
- Rename -loggerJsonFields to -loggerJSONFields for the sake of consistency naming commonly used in Go

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2348
This commit is contained in:
Aliaksandr Valialkin 2022-12-16 17:40:46 -08:00
parent cffd2f79a1
commit 2fad03d85e
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 4 additions and 37 deletions

View file

@ -1,32 +0,0 @@
package logger
import "strings"
var (
fieldTs = "ts"
fieldLevel = "level"
fieldCaller = "caller"
fieldMsg = "msg"
)
func setLoggerJSONFields() {
fields := strings.Split(*loggerJSONFields, ",")
for _, f := range fields {
v := strings.Split(strings.TrimSpace(f), ":")
if len(v) != 2 {
continue
}
old, new := v[0], v[1]
switch old {
case "ts":
fieldTs = new
case "level":
fieldLevel = new
case "caller":
fieldCaller = new
case "msg":
fieldMsg = new
}
}
}

View file

@ -17,11 +17,10 @@ import (
)
var (
loggerLevel = flag.String("loggerLevel", "INFO", "Minimum level of errors to log. Possible values: INFO, WARN, ERROR, FATAL, PANIC")
loggerFormat = flag.String("loggerFormat", "default", "Format for logs. Possible values: default, json")
loggerOutput = flag.String("loggerOutput", "stderr", "Output for the logs. Supported values: stderr, stdout")
loggerJSONFields = flag.String("loggerJsonFields", "", `Allows renaming fields in JSON formatted logs. Example: "ts:timestamp,msg:message" renames "ts" to "timestamp" and "msg" to "message"`)
loggerTimezone = flag.String("loggerTimezone", "UTC", "Timezone to use for timestamps in logs. Timezone must be a valid IANA Time Zone. "+
loggerLevel = flag.String("loggerLevel", "INFO", "Minimum level of errors to log. Possible values: INFO, WARN, ERROR, FATAL, PANIC")
loggerFormat = flag.String("loggerFormat", "default", "Format for logs. Possible values: default, json")
loggerOutput = flag.String("loggerOutput", "stderr", "Output for the logs. Supported values: stderr, stdout")
loggerTimezone = flag.String("loggerTimezone", "UTC", "Timezone to use for timestamps in logs. Timezone must be a valid IANA Time Zone. "+
"For example: America/New_York, Europe/Berlin, Etc/GMT+3 or Local")
disableTimestamps = flag.Bool("loggerDisableTimestamps", false, "Whether to disable writing timestamps in logs")