Allow to set "--LogLevel=<LogLevel>" when starting Wasabi from command line or from IDE.
MODIFY
WalletWasabi.Fluent.Desktop/Program.cs
WalletWasabi.Fluent.Desktop/Program.cs
@@ -16,6 +16,7 @@ using WalletWasabi.Logging;
using WalletWasabi.Services;
using WalletWasabi.Services.Terminate;
using WalletWasabi.Wallets;
+using LogLevel = WalletWasabi.Logging.LogLevel;
namespace WalletWasabi.Fluent.Desktop
{
@@ -59,6 +60,8 @@ namespace WalletWasabi.Fluent.Desktop
try
{
string dataDir = EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Client"));
+
+ SetupLogger(dataDir, args);
var (uiConfig, config) = LoadOrCreateConfigs(dataDir);
singleInstanceChecker = new SingleInstanceChecker(config.Network);
@@ -108,6 +111,31 @@ namespace WalletWasabi.Fluent.Desktop
return exceptionToReport is { } ? 1 : 0;
}
+ /// <summary>
+ /// Initializes Wasabi Logger. Sets user-defined log-level, if provided.
+ /// </summary>
+ /// <example>Start Wasabi Wallet with <c>./wassabee --LogLevel=trace</c> to set <see cref="LogLevel.Trace"/>.</example>
+ private static void SetupLogger(string dataDir, string[] args)
+ {
+ LogLevel? logLevel = null;
+
+ foreach (string arg in args)
+ {
+ if (arg.StartsWith("--LogLevel="))
+ {
+ string value = arg.Split('=', count: 2)[1];
+
+ if (Enum.TryParse(value, ignoreCase: true, out LogLevel parsedLevel))
+ {
+ logLevel = parsedLevel;
+ break;
+ }
+ }
+ }
+
+ Logger.InitializeDefaults(Path.Combine(dataDir, "Logs.txt"), logLevel);
+ }
+
private static (UiConfig uiConfig, Config config) LoadOrCreateConfigs(string dataDir)
{
Directory.CreateDirectory(dataDir);

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -86,8 +86,6 @@ namespace WalletWasabi.Gui
UiConfig = uiConfig;
TorSettings = new TorSettings(DataDir, torLogsFile, distributionFolderPath: EnvironmentHelpers.GetFullBaseDirectory());
- Logger.InitializeDefaults(Path.Combine(DataDir, "Logs.txt"));
-
HostedServices = new HostedServices();
WalletManager = walletManager;

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -68,6 +68,8 @@ namespace WalletWasabi.Gui
config.CorrectMixUntilAnonymitySet();
var walletManager = new WalletManager(config.Network, dataDir, new WalletDirectories(config.Network, dataDir));
+ Logger.InitializeDefaults(Path.Combine(dataDir, "Logs.txt"));
+
return new Global(dataDir, torLogsFile, config, uiConfig, walletManager);
}

MODIFY
WalletWasabi/Logging/Logger.cs
WalletWasabi/Logging/Logger.cs
@@ -54,21 +54,26 @@ namespace WalletWasabi.Logging
#region Initializers
/// <summary>
- /// Initializes the Logger with default values.
- ///
- /// <para>If RELEASE then <see cref="MinimumLevel"/> is set to <see cref="LogLevel.Info"/>, and logs only to file.</para>
- /// <para>If DEBUG then <see cref="MinimumLevel"/> is set to <see cref="LogLevel.Debug"/>, and logs to file, debug and console.</para>
+ /// Initializes the logger with default values.
+ /// <para>
+ /// Default values are set as follows:
+ /// <list type="bullet">
+ /// <item>For RELEASE mode: <see cref="MinimumLevel"/> is set to <see cref="LogLevel.Info"/>, and logs only to file.</item>
+ /// <item>For DEBUG mode: <see cref="MinimumLevel"/> is set to <see cref="LogLevel.Debug"/>, and logs to file, debug and console.</item>
+ /// </list>
+ /// </para>
/// </summary>
- public static void InitializeDefaults(string filePath)
+ /// <param name="logLevel">Use <c>null</c> to use default <see cref="LogLevel"/> or a custom value to force non-default <see cref="LogLevel"/>.</param>
+ public static void InitializeDefaults(string filePath, LogLevel? logLevel = null)
{
SetFilePath(filePath);
#if RELEASE
- SetMinimumLevel(LogLevel.Info);
+ SetMinimumLevel(logLevel ??= LogLevel.Info);
SetModes(LogMode.Console, LogMode.File);
#else
- SetMinimumLevel(LogLevel.Debug);
+ SetMinimumLevel(logLevel ??= LogLevel.Debug);
SetModes(LogMode.Debug, LogMode.Console, LogMode.File);
#endif
}

Allow to set "--LogLevel=<LogLevel>" when starting Wasabi from command line or from IDE.