Skip to content

Commit a9dfab2

Browse files
make logging on startup not dependent on host build
1 parent 4deaa0e commit a9dfab2

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Meddle/Meddle.Plugin/Plugin.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Dalamud.Configuration;
44
using Dalamud.IoC;
55
using Dalamud.Plugin;
6+
using Dalamud.Plugin.Services;
67
using Meddle.Plugin.Models;
78
using Meddle.Plugin.Services;
89
using Meddle.Plugin.UI.Layout;
@@ -20,11 +21,16 @@ public sealed class Plugin : IDalamudPlugin
2021
{
2122
public static readonly string DefaultExportDirectory = Path.Combine(Path.GetTempPath(), "Meddle.Export");
2223
private readonly IHost? app;
23-
private readonly ILogger<Plugin>? log;
24+
private readonly IPluginLog pluginLog;
2425
public static ILogger<Plugin>? Logger;
2526

2627
public Plugin(IDalamudPluginInterface pluginInterface)
2728
{
29+
var service = new Service();
30+
pluginInterface.Inject(service);
31+
pluginLog = service.GetLog() ?? throw new InvalidOperationException("Service log is null");
32+
pluginLog.Debug("Meddle Plugin initializing...");
33+
2834
try
2935
{
3036
#if HAS_LOCAL_CS
@@ -52,6 +58,7 @@ public Plugin(IDalamudPluginInterface pluginInterface)
5258
host.ConfigureServices(services =>
5359
{
5460
services.Configure<ConsoleLifetimeOptions>(options => options.SuppressStatusMessages = true);
61+
service.RegisterServices(services);
5562
services
5663
.AddServices(pluginInterface)
5764
.AddSingleton(config)
@@ -60,16 +67,15 @@ public Plugin(IDalamudPluginInterface pluginInterface)
6067
});
6168

6269
app = host.Build();
63-
log = app.Services.GetRequiredService<ILogger<Plugin>>();
64-
Logger = log;
70+
Logger = app.Services.GetRequiredService<ILogger<Plugin>>();
6571
Meddle.Utils.Global.Logger = app.Services.GetRequiredService<ILogger<Meddle.Utils.Global>>();
6672
NativeDll.Initialize(app.Services.GetRequiredService<IDalamudPluginInterface>().AssemblyLocation.DirectoryName);
6773

6874
app.Start();
6975
}
7076
catch (Exception e)
7177
{
72-
log?.LogError(e, "Failed to initialize plugin");
78+
pluginLog.Error(e, "Failed to initialize plugin");
7379
Dispose();
7480
}
7581
}
@@ -79,7 +85,7 @@ public void Dispose()
7985
app?.StopAsync();
8086
app?.WaitForShutdown();
8187
app?.Dispose();
82-
log?.LogDebug("Plugin disposed");
88+
pluginLog?.Debug("Plugin disposed");
8389
Alloc.Dispose();
8490
}
8591
}

Meddle/Meddle.Plugin/Service.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class Service
1919

2020
[PluginService]
2121
private IPluginLog PrivLog { get; set; } = null!;
22+
23+
public IPluginLog? GetLog() => PrivLog;
2224

2325
[PluginService]
2426
private IObjectTable ObjectTable { get; set; } = null!;

Meddle/Meddle.Plugin/ServiceUtility.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public static IServiceCollection AddUi(this IServiceCollection services)
3434

3535
public static IServiceCollection AddServices(this IServiceCollection services, IDalamudPluginInterface pluginInterface)
3636
{
37-
var service = new Service();
38-
pluginInterface.Inject(service);
39-
service.RegisterServices(services);
40-
4137
var serviceTypes = Assembly.GetExecutingAssembly().GetTypes()
4238
.Where(t => t is {IsClass: true, IsAbstract: false} && typeof(IService).IsAssignableFrom(t));
4339
foreach (var serviceType in serviceTypes)

0 commit comments

Comments
 (0)