From 11acca6215a9234c0ee055d6fef816d1bde933f8 Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Wed, 12 Mar 2025 12:01:39 +0800 Subject: [PATCH] Move log level to enum & Use info level as default --- Flow.Launcher.Infrastructure/Logger/Log.cs | 10 ++++++++-- Flow.Launcher.Infrastructure/UserSettings/Settings.cs | 4 +++- Flow.Launcher/App.xaml.cs | 8 ++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Logger/Log.cs b/Flow.Launcher.Infrastructure/Logger/Log.cs index 3eb53e0a3..2f368ac0c 100644 --- a/Flow.Launcher.Infrastructure/Logger/Log.cs +++ b/Flow.Launcher.Infrastructure/Logger/Log.cs @@ -66,13 +66,13 @@ namespace Flow.Launcher.Infrastructure.Logger public static void UseDebugLogLevel() { LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Debug, LogLevel.Fatal); - Info(nameof(Logger), "Using DEBUG log level."); + Info(nameof(Logger), "Using log level: DEBUG."); } public static void UseInfoLogLevel() { LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Info, LogLevel.Fatal); - Info(nameof(Logger), "Using INFO log level."); + Info(nameof(Logger), "Using log level: INFO."); } private static void LogFaultyFormat(string message) @@ -222,4 +222,10 @@ namespace Flow.Launcher.Infrastructure.Logger LogInternal(message, LogLevel.Warn); } } + + public enum LOGLEVEL + { + DEBUG, + INFO + } } diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 0a9d99777..93f6db111 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -5,6 +5,7 @@ using System.Text.Json.Serialization; using System.Windows; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Infrastructure.Hotkey; +using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; @@ -199,7 +200,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings } }; - public string LogLevel { get; set; } = "info"; + [JsonConverter(typeof(JsonStringEnumConverter))] + public LOGLEVEL LogLevel { get; set; } = LOGLEVEL.INFO; /// /// when false Alphabet static service will always return empty results diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 6ec0424b8..ec4bb8dc6 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -124,15 +124,11 @@ namespace Flow.Launcher switch (_settings.LogLevel) { - case "debug": + case LOGLEVEL.DEBUG: Log.UseDebugLogLevel(); break; - case "info": - Log.UseInfoLogLevel(); - break; default: - Log.Error(nameof(Flow.Launcher.App), "Unrecognized log level"); - Log.UseDebugLogLevel(); + Log.UseInfoLogLevel(); break; }