Skip to content

Commit

Permalink
Add stage id information to logs when loading plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Oct 2, 2023
1 parent 10ae287 commit d8656a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
using Edelstein.Protocol.Plugin;
using Edelstein.Application.Server.Configs;
using Edelstein.Protocol.Plugin;
using Microsoft.Extensions.Logging;

namespace Edelstein.Application.Server.Bootstraps;

public class StartPluginBootstrap<TContext> : IBootstrap
{
private readonly ILogger _logger;
private readonly ProgramConfigStage _config;
private readonly TContext _context;
private readonly IPluginManager<TContext> _manager;

public StartPluginBootstrap(
ILogger<StartPluginBootstrap<TContext>> logger,
TContext context,
ILogger<StartPluginBootstrap<TContext>> logger,
ProgramConfigStage config,
TContext context,
IPluginManager<TContext> manager
)
{
_logger = logger;
_config = config;
_context = context;
_manager = manager;
}

public int Priority => BootstrapPriority.Start;

public async Task Start()
Expand All @@ -29,13 +33,13 @@ public async Task Start()
foreach (var host in hosts)
{
await host.Plugin.OnInit(host, _context);
_logger.LogInformation("{Context} plugin {ID} initialised", typeof(TContext).Name, host.ID);
_logger.LogInformation("{ID} plugin initialised for {Stage} ({Context})", host.ID, _config.ID, typeof(TContext).Name);
}

foreach (var host in hosts)
{
await host.Plugin.OnStart(host, _context);
_logger.LogInformation("{Context} plugin {ID} started", typeof(TContext).Name, host.ID);
_logger.LogInformation("{ID} plugin started for {Stage} ({Context})", host.ID, _config.ID, typeof(TContext).Name);
}
}

Expand All @@ -46,7 +50,7 @@ public async Task Stop()
foreach (var host in hosts)
{
await host.Plugin.OnStop();
_logger.LogInformation("{Context} plugin {ID} stopped", typeof(TContext).Name, host.ID);
_logger.LogInformation("{ID} plugin stopped for {Stage} ({Context})", host.ID, _config.ID, typeof(TContext).Name);
}
}
}
4 changes: 4 additions & 0 deletions src/app/Edelstein.Application.Server/ProgramHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
b
.RegisterInstance(options)
.As<ILoginStageOptions>()
.As<ProgramConfigStage>()
.As<ProgramConfigStageLogin>()
.SingleInstance();
b.RegisterType<LoginContext>().SingleInstance();
Expand Down Expand Up @@ -191,6 +192,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
b
.RegisterInstance(options)
.As<IGameStageOptions>()
.As<ProgramConfigStage>()
.As<ProgramConfigStageGame>()
.SingleInstance();
b.RegisterType<GameContext>().SingleInstance();
Expand Down Expand Up @@ -237,6 +239,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
b
.RegisterInstance(options)
.As<IShopStageOptions>()
.As<ProgramConfigStage>()
.As<ProgramConfigStageShop>()
.SingleInstance();
b.RegisterType<ShopContext>().SingleInstance();
Expand Down Expand Up @@ -278,6 +281,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
b
.RegisterInstance(options)
.As<ITradeStageOptions>()
.As<ProgramConfigStage>()
.As<ProgramConfigStageTrade>()
.SingleInstance();
b.RegisterType<TradeContext>().SingleInstance();
Expand Down

0 comments on commit d8656a7

Please sign in to comment.