From 702ad7fafe104c9bb9e8a31680f47b2745737803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 14 Aug 2023 00:35:04 +0200 Subject: [PATCH] Add option for setting the logging format --- config.go | 9 +++++++++ main.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index ca01440..30b1f0c 100644 --- a/config.go +++ b/config.go @@ -13,6 +13,7 @@ type config struct { DBConnectionString string FaceitAPIKey string LogLevel string + LogFormat string } type channel struct { @@ -60,6 +61,7 @@ func readConfig(path string) (*config, error) { } config.LogLevel = "info" + config.LogFormat = "text" d = cfg.Get("log-level") if d != nil { if err := d.ParseParams(&config.LogLevel); err != nil { @@ -67,6 +69,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 + } + } + channels := make(map[string]channel) for _, channelDir := range cfg.GetAll("channel") { var name string diff --git a/main.go b/main.go index 6e70529..daa300d 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,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