Disable trace logging by default
This commit is contained in:
@@ -29,6 +29,7 @@ public class MareConfig : IMareConfiguration
|
||||
public bool InitialScanComplete { get; set; } = false;
|
||||
public LogLevel LogLevel { get; set; } = LogLevel.Information;
|
||||
public bool LogPerformance { get; set; } = false;
|
||||
public bool LogTraceLog { get; set; } = false;
|
||||
public bool LogEvents { get; set; } = true;
|
||||
public bool HoldCombatApplication { get; set; } = false;
|
||||
public double MaxLocalCacheInGiB { get; set; } = 20;
|
||||
|
||||
@@ -115,6 +115,7 @@ public class MarePlugin : MediatorSubscriberBase, IHostedService
|
||||
|
||||
private void DalamudUtilOnLogIn()
|
||||
{
|
||||
LoporritSync.Plugin.Self.ToggleFileLogging(_mareConfigService.Current.LogTraceLog, "Login");
|
||||
Logger?.LogDebug("Client login");
|
||||
if (_launchTask == null || _launchTask.IsCompleted) _launchTask = Task.Run(WaitForPlayerAndLaunchCharacterManager);
|
||||
}
|
||||
@@ -124,6 +125,7 @@ public class MarePlugin : MediatorSubscriberBase, IHostedService
|
||||
Logger?.LogDebug("Client logout");
|
||||
|
||||
_runtimeServiceScope?.Dispose();
|
||||
LoporritSync.Plugin.Self.ToggleFileLogging(true, "Logout");
|
||||
}
|
||||
|
||||
private async Task WaitForPlayerAndLaunchCharacterManager()
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace LoporritSync;
|
||||
public sealed class Plugin : IDalamudPlugin
|
||||
{
|
||||
private readonly IHost _host;
|
||||
private bool _traceLogEnabled = true;
|
||||
|
||||
#pragma warning disable CA2211, CS8618, MA0069, S1104, S2223
|
||||
public static Plugin Self;
|
||||
@@ -87,7 +88,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
{
|
||||
lb.ClearProviders();
|
||||
lb.AddDalamudLogging(pluginLog);
|
||||
lb.AddFile(Path.Combine(traceDir, $"mare-trace-{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.log"), (opt) =>
|
||||
lb.AddFile(Path.Combine(traceDir, $"trace-{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.log"), (opt) =>
|
||||
{
|
||||
opt.Append = true;
|
||||
opt.RollingFilesConvention = FileLoggerOptions.FileRollingConvention.Ascending;
|
||||
@@ -95,6 +96,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
opt.FileSizeLimitBytes = 50 * 1024 * 1024;
|
||||
});
|
||||
lb.SetMinimumLevel(LogLevel.Trace);
|
||||
lb.AddFilter<FileLoggerProvider>(_ => _traceLogEnabled);
|
||||
})
|
||||
.ConfigureServices(collection =>
|
||||
{
|
||||
@@ -250,7 +252,8 @@ public sealed class Plugin : IDalamudPlugin
|
||||
})
|
||||
.Build();
|
||||
|
||||
_ = Task.Run(async () => {
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await _host.StartAsync().ConfigureAwait(false);
|
||||
@@ -267,4 +270,11 @@ public sealed class Plugin : IDalamudPlugin
|
||||
_host.StopAsync().GetAwaiter().GetResult();
|
||||
_host.Dispose();
|
||||
}
|
||||
|
||||
public void ToggleFileLogging(bool enable, string reason)
|
||||
{
|
||||
_traceLogEnabled = true;
|
||||
_host.Services.GetService<ILogger<Plugin>>()?.LogInformation("File tracelog {enabled}: {reason}", enable ? "enabled" : "disabled", reason);
|
||||
_traceLogEnabled = enable;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ using MareSynchronos.WebAPI.Files.Models;
|
||||
using MareSynchronos.WebAPI.SignalR.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using System.Text.Json;
|
||||
@@ -679,6 +680,26 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
_configService.Save();
|
||||
}, _configService.Current.LogLevel);
|
||||
|
||||
bool logTraceToFile = _configService.Current.LogTraceLog;
|
||||
if (ImGui.Checkbox("Enable Trace Logging to File", ref logTraceToFile))
|
||||
{
|
||||
_configService.Current.LogTraceLog = logTraceToFile;
|
||||
_configService.Save();
|
||||
LoporritSync.Plugin.Self.ToggleFileLogging(_configService.Current.LogTraceLog, "Setting Change");
|
||||
}
|
||||
|
||||
ImGui.SameLine(300.0f * ImGuiHelpers.GlobalScale);
|
||||
if (_uiShared.IconTextButton(FontAwesomeIcon.FolderOpen, "Open TraceLog folder"))
|
||||
{
|
||||
ProcessStartInfo ps = new()
|
||||
{
|
||||
FileName = Path.Combine(_configService.ConfigurationDirectory, "tracelog"),
|
||||
UseShellExecute = true,
|
||||
WindowStyle = ProcessWindowStyle.Normal
|
||||
};
|
||||
Process.Start(ps);
|
||||
}
|
||||
|
||||
bool logPerformance = _configService.Current.LogPerformance;
|
||||
if (ImGui.Checkbox("Log Performance Counters", ref logPerformance))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user