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 2a229a319e
commit 70c720d640
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 47 additions and 0 deletions

View file

@ -16,6 +16,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
## tip
* FEATURE: support overriding of `-search.latencyOffset` value via URL param `latency_offset` when performing requests to [/api/v1/query](https://docs.victoriametrics.com/keyConcepts.html#instant-query) and [/api/v1/query_range](https://docs.victoriametrics.com/keyConcepts.html#range-query). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3481).
* FEATURE: allow changing field names in JSON logs if VictoriaMetrics components are started with `-loggerFormat=json` command-line flags. The field names can be changed with the `-loggerJSONFields` command-line flag. For example `-loggerJSONFields=ts:timestamp,msg:message` would rename `ts` and `msg` fields on the output JSON to `timestamp` and `message` fields. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2348). Thanks to @michal-kralik for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3488).
* BUGFIX: allow specifying values bigger than 2GiB to the following command-line flag values on 32-bit architectures (`386` and `arm`): `-storage.minFreeDiskSpaceBytes` and `-remoteWrite.maxDiskUsagePerURL`. Previously values bigger than 2GiB were incorrectly truncated on these architectures.
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): stop dropping metric name by a mistake on the [/metric-relabel-debug](https://docs.victoriametrics.com/vmagent.html#relabel-debug) page.

46
lib/logger/json_fields.go Normal file
View file

@ -0,0 +1,46 @@
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"
)