From e870dd27eb2016f7d8101660d4e4d5449f82b995 Mon Sep 17 00:00:00 2001
From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Wed, 29 May 2024 23:48:04 +0800
Subject: [PATCH 1/6] Allow log level selection
---
Flow.Launcher.Infrastructure/Logger/Log.cs | 22 +++++++++++++++----
.../UserSettings/Settings.cs | 2 ++
Flow.Launcher/App.xaml.cs | 14 ++++++++++++
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/Flow.Launcher.Infrastructure/Logger/Log.cs b/Flow.Launcher.Infrastructure/Logger/Log.cs
index d4bd473acf6..cce62a1ac66 100644
--- a/Flow.Launcher.Infrastructure/Logger/Log.cs
+++ b/Flow.Launcher.Infrastructure/Logger/Log.cs
@@ -48,17 +48,31 @@ static Log()
configuration.AddTarget("file", fileTargetASyncWrapper);
configuration.AddTarget("debug", debugTarget);
+ var fileRule = new LoggingRule("*", LogLevel.Debug, fileTargetASyncWrapper)
+ {
+ RuleName = "file"
+ };
#if DEBUG
- var fileRule = new LoggingRule("*", LogLevel.Debug, fileTargetASyncWrapper);
- var debugRule = new LoggingRule("*", LogLevel.Debug, debugTarget);
+ var debugRule = new LoggingRule("*", LogLevel.Debug, debugTarget)
+ {
+ RuleName = "debug"
+ };
configuration.LoggingRules.Add(debugRule);
-#else
- var fileRule = new LoggingRule("*", LogLevel.Info, fileTargetASyncWrapper);
#endif
configuration.LoggingRules.Add(fileRule);
LogManager.Configuration = configuration;
}
+ public static void UseDebugLogLevel()
+ {
+ LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Debug, LogLevel.Fatal);
+ }
+
+ public static void UseInfoLogLevel()
+ {
+ LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Info, LogLevel.Fatal);
+ }
+
private static void LogFaultyFormat(string message)
{
var logger = LogManager.GetLogger("FaultyLogger");
diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs
index 0fb6e2b3cbd..25beb8bf68b 100644
--- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs
+++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs
@@ -199,6 +199,8 @@ public CustomBrowserViewModel CustomBrowser
}
};
+ public string 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 447eca79267..6ec0424b863 100644
--- a/Flow.Launcher/App.xaml.cs
+++ b/Flow.Launcher/App.xaml.cs
@@ -122,6 +122,20 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
var imageLoadertask = ImageLoader.InitializeAsync();
+ switch (_settings.LogLevel)
+ {
+ case "debug":
+ Log.UseDebugLogLevel();
+ break;
+ case "info":
+ Log.UseInfoLogLevel();
+ break;
+ default:
+ Log.Error(nameof(Flow.Launcher.App), "Unrecognized log level");
+ Log.UseDebugLogLevel();
+ break;
+ }
+
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);
// TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future
From 44a90e53a918d3b580edb686b040d0c7cced8233 Mon Sep 17 00:00:00 2001
From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 11 Mar 2025 23:53:33 +0800
Subject: [PATCH 2/6] Write log level in log
---
Flow.Launcher.Infrastructure/Logger/Log.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Flow.Launcher.Infrastructure/Logger/Log.cs b/Flow.Launcher.Infrastructure/Logger/Log.cs
index cce62a1ac66..3eb53e0a3eb 100644
--- a/Flow.Launcher.Infrastructure/Logger/Log.cs
+++ b/Flow.Launcher.Infrastructure/Logger/Log.cs
@@ -66,11 +66,13 @@ static Log()
public static void UseDebugLogLevel()
{
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Debug, LogLevel.Fatal);
+ Info(nameof(Logger), "Using DEBUG log level.");
}
public static void UseInfoLogLevel()
{
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Info, LogLevel.Fatal);
+ Info(nameof(Logger), "Using INFO log level.");
}
private static void LogFaultyFormat(string message)
From 8d3fd756dd2ef5ed79113e9d4d4568b45820dbdf Mon Sep 17 00:00:00 2001
From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Wed, 12 Mar 2025 08:57:03 +0800
Subject: [PATCH 3/6] Add getter and setter
---
Flow.Launcher.Infrastructure/UserSettings/Settings.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs
index 25beb8bf68b..0a9d99777ec 100644
--- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs
+++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs
@@ -199,7 +199,7 @@ public CustomBrowserViewModel CustomBrowser
}
};
- public string LogLevel = "info";
+ public string LogLevel { get; set; } = "info";
///
/// when false Alphabet static service will always return empty results
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 4/6] 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 3eb53e0a3eb..2f368ac0c4d 100644
--- a/Flow.Launcher.Infrastructure/Logger/Log.cs
+++ b/Flow.Launcher.Infrastructure/Logger/Log.cs
@@ -66,13 +66,13 @@ static Log()
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 @@ public static void Warn(string message)
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 0a9d99777ec..93f6db111a2 100644
--- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs
+++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs
@@ -5,6 +5,7 @@
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 @@ public CustomBrowserViewModel CustomBrowser
}
};
- 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 6ec0424b863..ec4bb8dc650 100644
--- a/Flow.Launcher/App.xaml.cs
+++ b/Flow.Launcher/App.xaml.cs
@@ -124,15 +124,11 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
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;
}
From 05ff797613c952aedde47a1cfc55efe924ab6682 Mon Sep 17 00:00:00 2001
From: Jack Ye <1160210343@qq.com>
Date: Wed, 12 Mar 2025 12:26:29 +0800
Subject: [PATCH 5/6] Use one function to set log level
---
Flow.Launcher.Infrastructure/Logger/Log.cs | 20 ++++++++++++++++----
Flow.Launcher/App.xaml.cs | 12 ++----------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/Flow.Launcher.Infrastructure/Logger/Log.cs b/Flow.Launcher.Infrastructure/Logger/Log.cs
index 2f368ac0c4d..7f847e287d2 100644
--- a/Flow.Launcher.Infrastructure/Logger/Log.cs
+++ b/Flow.Launcher.Infrastructure/Logger/Log.cs
@@ -63,16 +63,28 @@ static Log()
LogManager.Configuration = configuration;
}
- public static void UseDebugLogLevel()
+ public static void SetLogLevel(LOGLEVEL level)
+ {
+ switch (level)
+ {
+ case LOGLEVEL.DEBUG:
+ UseDebugLogLevel();
+ break;
+ default:
+ UseInfoLogLevel();
+ break;
+ }
+ Info(nameof(Logger), $"Using log level: {level}.");
+ }
+
+ private static void UseDebugLogLevel()
{
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Debug, LogLevel.Fatal);
- Info(nameof(Logger), "Using log level: DEBUG.");
}
- public static void UseInfoLogLevel()
+ private static void UseInfoLogLevel()
{
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Info, LogLevel.Fatal);
- Info(nameof(Logger), "Using log level: INFO.");
}
private static void LogFaultyFormat(string message)
diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs
index ec4bb8dc650..ab68cf4266a 100644
--- a/Flow.Launcher/App.xaml.cs
+++ b/Flow.Launcher/App.xaml.cs
@@ -112,6 +112,8 @@ private async void OnStartupAsync(object sender, StartupEventArgs e)
{
await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
{
+ Log.SetLogLevel(_settings.LogLevel);
+
Ioc.Default.GetRequiredService().PreStartCleanUpAfterPortabilityUpdate();
Log.Info("|App.OnStartup|Begin Flow Launcher startup ----------------------------------------------------");
@@ -122,16 +124,6 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
var imageLoadertask = ImageLoader.InitializeAsync();
- switch (_settings.LogLevel)
- {
- case LOGLEVEL.DEBUG:
- Log.UseDebugLogLevel();
- break;
- default:
- Log.UseInfoLogLevel();
- break;
- }
-
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);
// TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future
From 66bf04642a6d9857dd2c91e23a0c5385b4ccddcc Mon Sep 17 00:00:00 2001
From: Jack Ye <1160210343@qq.com>
Date: Wed, 12 Mar 2025 12:33:26 +0800
Subject: [PATCH 6/6] Add log level change to general settings page
---
Flow.Launcher/Languages/en.xaml | 3 +++
.../SettingsPaneGeneralViewModel.cs | 22 +++++++++++++++++++
.../Views/SettingsPaneGeneral.xaml | 8 +++++++
3 files changed, 33 insertions(+)
diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml
index 058a51ae3fb..2ead21cf5b3 100644
--- a/Flow.Launcher/Languages/en.xaml
+++ b/Flow.Launcher/Languages/en.xaml
@@ -104,6 +104,9 @@
Always Preview
Always open preview panel when Flow activates. Press {0} to toggle preview.
Shadow effect is not allowed while current theme has blur effect enabled
+ Log level
+ Debug
+ Info
Search Plugin
diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs
index dddaa99d46e..e4f88432a39 100644
--- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs
+++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs
@@ -7,6 +7,7 @@
using Flow.Launcher.Core.Configuration;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
+using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedModels;
@@ -31,6 +32,7 @@ public class SearchWindowScreenData : DropdownDataGeneric {
public class SearchWindowAlignData : DropdownDataGeneric { }
public class SearchPrecisionData : DropdownDataGeneric { }
public class LastQueryModeData : DropdownDataGeneric { }
+ public class LogLevelData : DropdownDataGeneric { }
public bool StartFlowLauncherOnSystemStartup
{
@@ -143,12 +145,16 @@ public bool PortableMode
public List LastQueryModes { get; } =
DropdownDataGeneric.GetValues("LastQuery");
+ public List LogLevels { get; } =
+ DropdownDataGeneric.GetValues("LogLevel");
+
private void UpdateEnumDropdownLocalizations()
{
DropdownDataGeneric.UpdateLabels(SearchWindowScreens);
DropdownDataGeneric.UpdateLabels(SearchWindowAligns);
DropdownDataGeneric.UpdateLabels(SearchPrecisionScores);
DropdownDataGeneric.UpdateLabels(LastQueryModes);
+ DropdownDataGeneric.UpdateLabels(LogLevels);
}
public string Language
@@ -216,6 +222,22 @@ public bool AutoUpdates
}
}
+ public LOGLEVEL LogLevel
+ {
+ get => Settings.LogLevel;
+ set
+ {
+ if (Settings.LogLevel != value)
+ {
+ Settings.LogLevel = value;
+
+ Log.SetLogLevel(value);
+
+ UpdateEnumDropdownLocalizations();
+ }
+ }
+ }
+
[RelayCommand]
private void SelectPython()
{
diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml
index a80e618e8b4..814eda16bd9 100644
--- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml
+++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml
@@ -278,6 +278,14 @@
SelectedValue="{Binding Language}"
SelectedValuePath="LanguageCode" />
+
+
+
+