Skip to content

Commit 9b2148f

Browse files
Merge pull request #2739 from Flow-Launcher/debug-log-level
Allow log level selection
2 parents 68afe86 + 66bf046 commit 9b2148f

File tree

6 files changed

+77
-4
lines changed

6 files changed

+77
-4
lines changed

Flow.Launcher.Infrastructure/Logger/Log.cs

+38-4
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,45 @@ static Log()
4848
configuration.AddTarget("file", fileTargetASyncWrapper);
4949
configuration.AddTarget("debug", debugTarget);
5050

51+
var fileRule = new LoggingRule("*", LogLevel.Debug, fileTargetASyncWrapper)
52+
{
53+
RuleName = "file"
54+
};
5155
#if DEBUG
52-
var fileRule = new LoggingRule("*", LogLevel.Debug, fileTargetASyncWrapper);
53-
var debugRule = new LoggingRule("*", LogLevel.Debug, debugTarget);
56+
var debugRule = new LoggingRule("*", LogLevel.Debug, debugTarget)
57+
{
58+
RuleName = "debug"
59+
};
5460
configuration.LoggingRules.Add(debugRule);
55-
#else
56-
var fileRule = new LoggingRule("*", LogLevel.Info, fileTargetASyncWrapper);
5761
#endif
5862
configuration.LoggingRules.Add(fileRule);
5963
LogManager.Configuration = configuration;
6064
}
6165

66+
public static void SetLogLevel(LOGLEVEL level)
67+
{
68+
switch (level)
69+
{
70+
case LOGLEVEL.DEBUG:
71+
UseDebugLogLevel();
72+
break;
73+
default:
74+
UseInfoLogLevel();
75+
break;
76+
}
77+
Info(nameof(Logger), $"Using log level: {level}.");
78+
}
79+
80+
private static void UseDebugLogLevel()
81+
{
82+
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Debug, LogLevel.Fatal);
83+
}
84+
85+
private static void UseInfoLogLevel()
86+
{
87+
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Info, LogLevel.Fatal);
88+
}
89+
6290
private static void LogFaultyFormat(string message)
6391
{
6492
var logger = LogManager.GetLogger("FaultyLogger");
@@ -206,4 +234,10 @@ public static void Warn(string message)
206234
LogInternal(message, LogLevel.Warn);
207235
}
208236
}
237+
238+
public enum LOGLEVEL
239+
{
240+
DEBUG,
241+
INFO
242+
}
209243
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Windows;
66
using CommunityToolkit.Mvvm.DependencyInjection;
77
using Flow.Launcher.Infrastructure.Hotkey;
8+
using Flow.Launcher.Infrastructure.Logger;
89
using Flow.Launcher.Infrastructure.Storage;
910
using Flow.Launcher.Plugin;
1011
using Flow.Launcher.Plugin.SharedModels;
@@ -199,6 +200,9 @@ public CustomBrowserViewModel CustomBrowser
199200
}
200201
};
201202

203+
[JsonConverter(typeof(JsonStringEnumConverter))]
204+
public LOGLEVEL LogLevel { get; set; } = LOGLEVEL.INFO;
205+
202206
/// <summary>
203207
/// when false Alphabet static service will always return empty results
204208
/// </summary>

Flow.Launcher/App.xaml.cs

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ private async void OnStartupAsync(object sender, StartupEventArgs e)
112112
{
113113
await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
114114
{
115+
Log.SetLogLevel(_settings.LogLevel);
116+
115117
Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();
116118

117119
Log.Info("|App.OnStartup|Begin Flow Launcher startup ----------------------------------------------------");

Flow.Launcher/Languages/en.xaml

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
<system:String x:Key="AlwaysPreview">Always Preview</system:String>
105105
<system:String x:Key="AlwaysPreviewToolTip">Always open preview panel when Flow activates. Press {0} to toggle preview.</system:String>
106106
<system:String x:Key="shadowEffectNotAllowed">Shadow effect is not allowed while current theme has blur effect enabled</system:String>
107+
<system:String x:Key="logLevel">Log level</system:String>
108+
<system:String x:Key="LogLevelDEBUG">Debug</system:String>
109+
<system:String x:Key="LogLevelINFO">Info</system:String>
107110

108111
<!-- Setting Plugin -->
109112
<system:String x:Key="searchplugin">Search Plugin</system:String>

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

+22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Flow.Launcher.Core.Configuration;
88
using Flow.Launcher.Core.Resource;
99
using Flow.Launcher.Helper;
10+
using Flow.Launcher.Infrastructure.Logger;
1011
using Flow.Launcher.Infrastructure.UserSettings;
1112
using Flow.Launcher.Plugin;
1213
using Flow.Launcher.Plugin.SharedModels;
@@ -31,6 +32,7 @@ public class SearchWindowScreenData : DropdownDataGeneric<SearchWindowScreens> {
3132
public class SearchWindowAlignData : DropdownDataGeneric<SearchWindowAligns> { }
3233
public class SearchPrecisionData : DropdownDataGeneric<SearchPrecisionScore> { }
3334
public class LastQueryModeData : DropdownDataGeneric<LastQueryMode> { }
35+
public class LogLevelData : DropdownDataGeneric<LOGLEVEL> { }
3436

3537
public bool StartFlowLauncherOnSystemStartup
3638
{
@@ -143,12 +145,16 @@ public bool PortableMode
143145
public List<LastQueryModeData> LastQueryModes { get; } =
144146
DropdownDataGeneric<LastQueryMode>.GetValues<LastQueryModeData>("LastQuery");
145147

148+
public List<LogLevelData> LogLevels { get; } =
149+
DropdownDataGeneric<LOGLEVEL>.GetValues<LogLevelData>("LogLevel");
150+
146151
private void UpdateEnumDropdownLocalizations()
147152
{
148153
DropdownDataGeneric<SearchWindowScreens>.UpdateLabels(SearchWindowScreens);
149154
DropdownDataGeneric<SearchWindowAligns>.UpdateLabels(SearchWindowAligns);
150155
DropdownDataGeneric<SearchPrecisionScore>.UpdateLabels(SearchPrecisionScores);
151156
DropdownDataGeneric<LastQueryMode>.UpdateLabels(LastQueryModes);
157+
DropdownDataGeneric<LOGLEVEL>.UpdateLabels(LogLevels);
152158
}
153159

154160
public string Language
@@ -216,6 +222,22 @@ public bool AutoUpdates
216222
}
217223
}
218224

225+
public LOGLEVEL LogLevel
226+
{
227+
get => Settings.LogLevel;
228+
set
229+
{
230+
if (Settings.LogLevel != value)
231+
{
232+
Settings.LogLevel = value;
233+
234+
Log.SetLogLevel(value);
235+
236+
UpdateEnumDropdownLocalizations();
237+
}
238+
}
239+
}
240+
219241
[RelayCommand]
220242
private void SelectPython()
221243
{

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

+8
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@
278278
SelectedValue="{Binding Language}"
279279
SelectedValuePath="LanguageCode" />
280280
</cc:Card>
281+
282+
<cc:Card Title="{DynamicResource logLevel}" Margin="0 14 0 0">
283+
<ComboBox
284+
DisplayMemberPath="Display"
285+
ItemsSource="{Binding LogLevels}"
286+
SelectedValue="{Binding LogLevel}"
287+
SelectedValuePath="Value" />
288+
</cc:Card>
281289
</VirtualizingStackPanel>
282290
</ScrollViewer>
283291
</ui:Page>

0 commit comments

Comments
 (0)