lib/logger: exit the app if unsupported timezone value has been passed to -loggerTimezone

While at it, clarify descrption for `-loggerTimezone` command-line flag.
This commit is contained in:
Aliaksandr Valialkin 2021-02-07 23:31:42 +02:00
parent 9b9cb04511
commit 8f28a578d3

View file

@ -17,10 +17,11 @@ import (
) )
var ( var (
loggerLevel = flag.String("loggerLevel", "INFO", "Minimum level of errors to log. Possible values: INFO, WARN, ERROR, FATAL, PANIC") 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") 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") 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. Local timezone can be used") 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") disableTimestamps = flag.Bool("loggerDisableTimestamps", false, "Whether to disable writing timestamps in logs")
errorsPerSecondLimit = flag.Int("loggerErrorsPerSecondLimit", 0, "Per-second limit on the number of ERROR messages. If more than the given number of errors "+ errorsPerSecondLimit = flag.Int("loggerErrorsPerSecondLimit", 0, "Per-second limit on the number of ERROR messages. If more than the given number of errors "+
@ -47,8 +48,7 @@ func Init() {
func initTimezone() { func initTimezone() {
tz, err := time.LoadLocation(*loggerTimezone) tz, err := time.LoadLocation(*loggerTimezone)
if err != nil { if err != nil {
log.Printf("cannot load timezone %q, so using UTC; error: %s", *loggerTimezone, err) log.Fatalf("cannot load timezone %q: %s", *loggerTimezone, err)
tz = time.UTC
} }
timezone = tz timezone = tz
} }