From b3fb36d5cc7f05863bcbf0fe7543bfcdb9e54b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 14 Aug 2023 01:08:24 +0200 Subject: [PATCH] Add option for setting the logging format --- config/config.go | 9 +++++++++ server.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 98bcacb..c9de902 100644 --- a/config/config.go +++ b/config/config.go @@ -11,6 +11,7 @@ type Config struct { HTTPAddress string DBConnectionString string LogLevel string + LogFormat string EnablePlayground bool Admins []string Maps []string @@ -26,6 +27,7 @@ func ReadConfig(path string) (*Config, error) { // Set default values config.HTTPAddress = "127.0.0.1:8080" config.LogLevel = "info" + config.LogFormat = "text" config.EnablePlayground = false d := cfg.Get("http-address") @@ -50,6 +52,13 @@ func ReadConfig(path string) (*Config, error) { } } + d = cfg.Get("log-format") + if d != nil { + if err := d.ParseParams(&config.LogFormat); err != nil { + return nil, err + } + } + d = cfg.Get("enable-playground") if d != nil { var enablePlayground string diff --git a/server.go b/server.go index f06b6c8..858bc96 100644 --- a/server.go +++ b/server.go @@ -33,7 +33,7 @@ func main() { os.Exit(1) } - logger, err := logging.New(cfg.LogLevel, "text", os.Stderr) + logger, err := logging.New(cfg.LogLevel, cfg.LogFormat, os.Stderr) if err != nil { slog.Error("Failed to create logger", slog.String("error", err.Error())) -- 2.44.0