Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow log level selection #2739

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Flow.Launcher.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public CustomBrowserViewModel CustomBrowser
}
};

public string LogLevel = "info";

/// <summary>
/// when false Alphabet static service will always return empty results
Expand Down
14 changes: 14 additions & 0 deletions Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
_settings = _settingsVM.Settings;
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();

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);

_alphabet.Initialize(_settings);
Expand Down
Loading