From 8f28a578d3ded2662e94ab193abe02553bcf8287 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 7 Feb 2021 23:31:42 +0200 Subject: [PATCH] lib/logger: exit the app if unsupported timezone value has been passed to `-loggerTimezone` While at it, clarify descrption for `-loggerTimezone` command-line flag. --- lib/logger/logger.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/logger/logger.go b/lib/logger/logger.go index 1e49c29c4..862aec8b2 100644 --- a/lib/logger/logger.go +++ b/lib/logger/logger.go @@ -17,10 +17,11 @@ import ( ) 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") - loggerTimezone = flag.String("loggerTimezone", "UTC", "Timezone to use for timestamps in logs. Local timezone can be used") + 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") + 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") 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() { tz, err := time.LoadLocation(*loggerTimezone) if err != nil { - log.Printf("cannot load timezone %q, so using UTC; error: %s", *loggerTimezone, err) - tz = time.UTC + log.Fatalf("cannot load timezone %q: %s", *loggerTimezone, err) } timezone = tz }