mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
72f8fce107
commit
4cb83f0f4a
4 changed files with 51 additions and 37 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
46
lib/logger/json_fields.go
Normal file
46
lib/logger/json_fields.go
Normal 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"
|
||||
)
|
|
@ -20,7 +20,6 @@ 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. "+
|
||||
"For example: America/New_York, Europe/Berlin, Etc/GMT+3 or Local")
|
||||
disableTimestamps = flag.Bool("loggerDisableTimestamps", false, "Whether to disable writing timestamps in logs")
|
||||
|
|
Loading…
Reference in a new issue