From cfa7724b68c957e09e1bb0475eea6134cca9d4a2 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 30 Jul 2025 20:16:49 +0300 Subject: [PATCH] add exception for unknown logging level --- hooks/initial.go | 6 ++++++ internal/engine/logs/logger.go | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/hooks/initial.go b/hooks/initial.go index d606d33..5526413 100644 --- a/hooks/initial.go +++ b/hooks/initial.go @@ -179,6 +179,12 @@ func Init6Hook(cs *corestate.CoreState, x *app.AppX) { replaced := strings.ReplaceAll(*x.Config.Conf.Log.OutPath, "%tmp%", filepath.Clean(run_manager.RuntimeDir())) x.Config.Conf.Log.OutPath = &replaced } + if !slices.Contains(logs.Levels.Available, *x.Config.Conf.Log.Level) { + if !slices.Contains(*x.Config.Conf.DisableWarnings, "--WUndefLogLevel") { + x.Log.Printf("%s: %s", logs.PrintWarn(), fmt.Sprintf("Unknown logging level %s, fallback level: %s", *x.Config.Conf.Log.Level, logs.Levels.Fallback)) + } + x.Config.Conf.Log.Level = &logs.Levels.Fallback + } } func Init7Hook(cs *corestate.CoreState, x *app.AppX) { diff --git a/internal/engine/logs/logger.go b/internal/engine/logs/logger.go index 459dff2..5bd8746 100644 --- a/internal/engine/logs/logger.go +++ b/internal/engine/logs/logger.go @@ -16,6 +16,17 @@ import ( ) var GlobalLevel slog.Level +type levelsStruct struct { + Available []string + Fallback string +} + +var Levels = levelsStruct{ + Available: []string{ + "debug", "info", + }, + Fallback: "info", +} type SlogWriter struct { Logger *slog.Logger