diff --git a/internal/logging/logging.go b/internal/logging/logging.go index 41632d3..6a9f185 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -1,6 +1,8 @@ package logging import ( + "fmt" + "strings" "time" "github.com/dop251/goja" @@ -57,14 +59,30 @@ func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { return &Logging{vu: vu} } + val, ok := vu.InitEnv().LookupEnv("DATE_FORMAT") + tsFormat, disableTs := time.TimeOnly, false + if ok { + switch strings.ToLower(val) { + case "timeonly": + case "datetime": + tsFormat = time.DateTime + case "none": + disableTs = true + default: + panic(fmt.Sprintf("invalid value for DATE_FORMAT: %s (should be `timeonly` or `datetime`)", val)) + } + } + format := lg.Formatter switch f := format.(type) { case *logrus.TextFormatter: f.ForceColors = true f.FullTimestamp = true - f.TimestampFormat = time.TimeOnly + f.TimestampFormat = tsFormat + f.DisableTimestamp = disableTs case *logrus.JSONFormatter: - f.TimestampFormat = time.TimeOnly + f.TimestampFormat = tsFormat + f.DisableTimestamp = disableTs } return &Logging{vu: vu} diff --git a/scenarios/run_scenarios.md b/scenarios/run_scenarios.md index 091adc9..144793c 100644 --- a/scenarios/run_scenarios.md +++ b/scenarios/run_scenarios.md @@ -21,6 +21,7 @@ Scenarios `grpc.js`, `local.js`, `http.js` and `s3.js` support the following opt * `PAYLOAD_TYPE` - type of an object payload ("random" or "text", default: "random"). * `STREAMING` - if set, the payload is generated on the fly and is not read into memory fully. * `METRIC_TAGS` - custom metrics tags (format `tag1:value1;tag2:value2`). + * `DATE_FORMAT` - custom datetime format: `timeonly` (default), `datetime` or `none`. Additionally, the profiling extension can be enabled to generate CPU and memory profiles which can be inspected with `go tool pprof file.prof`: ```shell