From cad8dfb673a2c163542e2f98c0103df64d173d56 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Mon, 1 Mar 2021 00:25:16 +0100 Subject: [PATCH] Allow to disable log color output (#288) Co-authored-by: CrazyMax --- docs/usage/cli.md | 2 ++ internal/logging/logger.go | 1 + internal/model/cli.go | 13 +++++++------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/usage/cli.md b/docs/usage/cli.md index 83cddd45..1aaad563 100644 --- a/docs/usage/cli.md +++ b/docs/usage/cli.md @@ -21,6 +21,7 @@ Flags: --log-level="info" Set log level ($LOG_LEVEL). --log-json Enable JSON logging output ($LOG_JSON). --log-caller Add file:line of the caller to log output ($LOG_CALLER). + --log-nocolor Disables the colorized output ($LOG_NOCOLOR). --test-notif Test notification settings. ``` @@ -34,3 +35,4 @@ Following environment variables can be used in place: | `LOG_LEVEL` | `info` | Log level output | | `LOG_JSON` | `false` | Enable JSON logging output | | `LOG_CALLER` | `false` | Enable to add `file:line` of the caller | +| `LOG_NOCOLOR` | `false` | Disables the colorized output | diff --git a/internal/logging/logger.go b/internal/logging/logger.go index 64564d9a..ad91ede3 100644 --- a/internal/logging/logger.go +++ b/internal/logging/logger.go @@ -20,6 +20,7 @@ func Configure(cli *model.Cli) { if !cli.LogJSON { w = zerolog.ConsoleWriter{ Out: os.Stdout, + NoColor: cli.LogNoColor, TimeFormat: time.RFC1123, } } else { diff --git a/internal/model/cli.go b/internal/model/cli.go index f0a7ded3..ce70bcea 100644 --- a/internal/model/cli.go +++ b/internal/model/cli.go @@ -4,10 +4,11 @@ import "github.com/alecthomas/kong" // Cli holds command line args, flags and cmds type Cli struct { - Version kong.VersionFlag - Cfgfile string `kong:"name='config',env='CONFIG',help='Diun configuration file.'"` - LogLevel string `kong:"name='log-level',env='LOG_LEVEL',default='info',help='Set log level.'"` - LogJSON bool `kong:"name='log-json',env='LOG_JSON',default='false',help='Enable JSON logging output.'"` - LogCaller bool `kong:"name='log-caller',env='LOG_CALLER',default='false',help='Add file:line of the caller to log output.'"` - TestNotif bool `kong:"name='test-notif',default='false',help='Test notification settings.'"` + Version kong.VersionFlag + Cfgfile string `kong:"name='config',env='CONFIG',help='Diun configuration file.'"` + LogLevel string `kong:"name='log-level',env='LOG_LEVEL',default='info',help='Set log level.'"` + LogJSON bool `kong:"name='log-json',env='LOG_JSON',default='false',help='Enable JSON logging output.'"` + LogCaller bool `kong:"name='log-caller',env='LOG_CALLER',default='false',help='Add file:line of the caller to log output.'"` + LogNoColor bool `kong:"name='log-nocolor',env='LOG_NOCOLOR',default='false',help='Disables the colorized output.'"` + TestNotif bool `kong:"name='test-notif',default='false',help='Test notification settings.'"` }