~xenrox/10man-api

b3fb36d5cc7f05863bcbf0fe7543bfcdb9e54b6a — Thorben Günther 8 months ago 35a47d8
Add option for setting the logging format
2 files changed, 10 insertions(+), 1 deletions(-)

M config/config.go
M server.go
M config/config.go => config/config.go +9 -0
@@ 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

M server.go => server.go +1 -1
@@ 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()))