From aca6d33548beee919276bb6d35f150d48dcb1202 Mon Sep 17 00:00:00 2001 From: Matt Hook Date: Wed, 14 Feb 2024 07:54:47 +1300 Subject: [PATCH] fix(logs): add NOCOLOR option for use when exporting to greylog etc [EE-6696] (#11107) --- api/cli/cli.go | 2 +- api/cmd/portainer/log.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/cli/cli.go b/api/cli/cli.go index d951d71b3..32c60910f 100644 --- a/api/cli/cli.go +++ b/api/cli/cli.go @@ -62,7 +62,7 @@ func (*Service) ParseFlags(version string) (*portainer.CLIFlags, error) { MaxBatchDelay: kingpin.Flag("max-batch-delay", "Maximum delay before a batch starts").Duration(), SecretKeyName: kingpin.Flag("secret-key-name", "Secret key name for encryption and will be used as /run/secrets/.").Default(defaultSecretKeyName).String(), LogLevel: kingpin.Flag("log-level", "Set the minimum logging level to show").Default("INFO").Enum("DEBUG", "INFO", "WARN", "ERROR"), - LogMode: kingpin.Flag("log-mode", "Set the logging output mode").Default("PRETTY").Enum("PRETTY", "JSON"), + LogMode: kingpin.Flag("log-mode", "Set the logging output mode").Default("PRETTY").Enum("NOCOLOR", "PRETTY", "JSON"), } kingpin.Parse() diff --git a/api/cmd/portainer/log.go b/api/cmd/portainer/log.go index 63eaf872d..7ec861421 100644 --- a/api/cmd/portainer/log.go +++ b/api/cmd/portainer/log.go @@ -42,6 +42,13 @@ func setLoggingMode(mode string) { TimeFormat: "2006/01/02 03:04PM", FormatMessage: formatMessage, }) + case "NOCOLOR": + log.Logger = log.Output(zerolog.ConsoleWriter{ + Out: os.Stderr, + TimeFormat: "2006/01/02 03:04PM", + FormatMessage: formatMessage, + NoColor: true, + }) case "JSON": log.Logger = log.Output(os.Stderr) }