Allow log level selection

This commit is contained in:
VictoriousRaptor 2024-05-29 23:48:04 +08:00
parent 36e10a175c
commit e870dd27eb
3 changed files with 34 additions and 4 deletions

View file

@ -48,17 +48,31 @@ namespace Flow.Launcher.Infrastructure.Logger
configuration.AddTarget("file", fileTargetASyncWrapper); configuration.AddTarget("file", fileTargetASyncWrapper);
configuration.AddTarget("debug", debugTarget); configuration.AddTarget("debug", debugTarget);
var fileRule = new LoggingRule("*", LogLevel.Debug, fileTargetASyncWrapper)
{
RuleName = "file"
};
#if DEBUG #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); configuration.LoggingRules.Add(debugRule);
#else
var fileRule = new LoggingRule("*", LogLevel.Info, fileTargetASyncWrapper);
#endif #endif
configuration.LoggingRules.Add(fileRule); configuration.LoggingRules.Add(fileRule);
LogManager.Configuration = configuration; 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) private static void LogFaultyFormat(string message)
{ {
var logger = LogManager.GetLogger("FaultyLogger"); var logger = LogManager.GetLogger("FaultyLogger");

View file

@ -199,6 +199,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings
} }
}; };
public string LogLevel = "info";
/// <summary> /// <summary>
/// when false Alphabet static service will always return empty results /// when false Alphabet static service will always return empty results
/// </summary> /// </summary>

View file

@ -122,6 +122,20 @@ namespace Flow.Launcher
var imageLoadertask = ImageLoader.InitializeAsync(); 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); AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);
// TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future // TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future