mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-05 01:01:09 +01:00
4cb83f0f4a
- 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
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package logger
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
var loggerJSONFields = flag.String("loggerJSONFields", "", `Allows renaming fields in JSON formatted logs. `+
|
|
`Example: "ts:timestamp,msg:message" renames "ts" to "timestamp" and "msg" to "message". `+
|
|
"Supported fields: ts, level, caller, msg")
|
|
|
|
func setLoggerJSONFields() {
|
|
if *loggerJSONFields == "" {
|
|
return
|
|
}
|
|
fields := strings.Split(*loggerJSONFields, ",")
|
|
for _, f := range fields {
|
|
f = strings.TrimSpace(f)
|
|
v := strings.Split(f, ":")
|
|
if len(v) != 2 {
|
|
log.Fatalf("missing ':' delimiter in -loggerJSONFields=%q for %q item", *loggerJSONFields, f)
|
|
}
|
|
|
|
name, value := v[0], v[1]
|
|
switch name {
|
|
case "ts":
|
|
fieldTs = value
|
|
case "level":
|
|
fieldLevel = value
|
|
case "caller":
|
|
fieldCaller = value
|
|
case "msg":
|
|
fieldMsg = value
|
|
default:
|
|
log.Fatalf("unexpected json field name in -loggerJSONFields=%q: %q; supported values: ts, level, caller, msg", *loggerJSONFields, name)
|
|
}
|
|
}
|
|
}
|
|
|
|
var (
|
|
fieldTs = "ts"
|
|
fieldLevel = "level"
|
|
fieldCaller = "caller"
|
|
fieldMsg = "msg"
|
|
)
|