Allow event logging to be disabled

This commit is contained in:
Loporrit
2025-02-09 05:21:51 +00:00
parent e8ae2a6152
commit 6f88ed1ea5
4 changed files with 17 additions and 9 deletions

View File

@@ -21,6 +21,7 @@ public class MareConfig : IMareConfiguration
public bool InitialScanComplete { get; set; } = false; public bool InitialScanComplete { get; set; } = false;
public LogLevel LogLevel { get; set; } = LogLevel.Information; public LogLevel LogLevel { get; set; } = LogLevel.Information;
public bool LogPerformance { get; set; } = false; public bool LogPerformance { get; set; } = false;
public bool LogEvents { get; set; } = true;
public double MaxLocalCacheInGiB { get; set; } = 20; public double MaxLocalCacheInGiB { get; set; } = 20;
public bool OpenGposeImportOnGposeStart { get; set; } = false; public bool OpenGposeImportOnGposeStart { get; set; } = false;
public bool OpenPopupOnAdd { get; set; } = true; public bool OpenPopupOnAdd { get; set; } = true;

View File

@@ -92,8 +92,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton<FileCompactor>(); collection.AddSingleton<FileCompactor>();
collection.AddSingleton<TagHandler>(); collection.AddSingleton<TagHandler>();
collection.AddSingleton<UidDisplayHandler>(); collection.AddSingleton<UidDisplayHandler>();
collection.AddSingleton((s) => new EventAggregator(pluginInterface.ConfigDirectory.FullName, collection.AddSingleton<EventAggregator>();
s.GetRequiredService<ILogger<EventAggregator>>(), s.GetRequiredService<MareMediator>()));
collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(), collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(),
clientState, objectTable, framework, gameGui, toastGui, condition, gameData, targetManager, clientState, objectTable, framework, gameGui, toastGui, condition, gameData, targetManager,
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PerformanceCollectorService>())); s.GetRequiredService<MareMediator>(), s.GetRequiredService<PerformanceCollectorService>()));

View File

@@ -1,4 +1,5 @@
using MareSynchronos.Services.Mediator; using MareSynchronos.MareConfiguration;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Utils; using MareSynchronos.Utils;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -18,19 +19,22 @@ public class EventAggregator : MediatorSubscriberBase, IHostedService
private string CurrentLogName => $"{DateTime.Now:yyyy-MM-dd}-events.log"; private string CurrentLogName => $"{DateTime.Now:yyyy-MM-dd}-events.log";
private DateTime _currentTime; private DateTime _currentTime;
public EventAggregator(string configDirectory, ILogger<EventAggregator> logger, MareMediator mareMediator) : base(logger, mareMediator) public EventAggregator(MareConfigService configService, ILogger<EventAggregator> logger, MareMediator mareMediator) : base(logger, mareMediator)
{ {
Logger.LogInformation("Starting EventAggregatorService"); Logger.LogInformation("Starting EventAggregatorService");
Logger.LogInformation("Started EventAggregatorService"); Logger.LogInformation("Started EventAggregatorService");
_configDirectory = configService.ConfigurationDirectory;
_logger = logger;
_currentTime = DateTime.UnixEpoch;
Mediator.Subscribe<EventMessage>(this, (msg) => Mediator.Subscribe<EventMessage>(this, (msg) =>
{ {
_lock.Wait(); _lock.Wait();
try try
{ {
Logger.LogTrace("Received Event: {evt}", msg.Event.ToString());
_events.Add(msg.Event); _events.Add(msg.Event);
WriteToFile(msg.Event); if (configService.Current.LogEvents)
WriteToFile(msg.Event);
} }
finally finally
{ {
@@ -41,9 +45,6 @@ public class EventAggregator : MediatorSubscriberBase, IHostedService
}); });
EventList = CreateEventLazy(); EventList = CreateEventLazy();
_configDirectory = configDirectory;
_logger = logger;
_currentTime = DateTime.Now - TimeSpan.FromDays(1);
} }
private void RecreateLazy() private void RecreateLazy()

View File

@@ -661,6 +661,13 @@ public class SettingsUi : WindowMediatorSubscriberBase
{ {
_performanceCollector.PrintPerformanceStats(60); _performanceCollector.PrintPerformanceStats(60);
} }
bool logEvents = _configService.Current.LogEvents;
if (ImGui.Checkbox("Log Event Viewer Data", ref logEvents))
{
_configService.Current.LogEvents = logEvents;
_configService.Save();
}
} }
private void DrawFileStorageSettings() private void DrawFileStorageSettings()