feat(scripting): root script logger + DPS publisher wired in Host
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Scripting;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Host.Logging;
|
||||
|
||||
/// <summary>
|
||||
/// Composes the root script <see cref="Serilog.ILogger"/> — the single pipeline every
|
||||
/// per-script logger derives from. Fans each script log event out to three destinations:
|
||||
/// a dedicated rolling <c>scripts-*.log</c> file, the main server log (via
|
||||
/// <see cref="ScriptLogCompanionSink"/>, mirroring Error-or-higher events at Warning), and
|
||||
/// the cluster <c>script-logs</c> DPS topic (via <see cref="ScriptLogTopicSink"/>) so the
|
||||
/// live Script-log Admin UI page can tail script output.
|
||||
/// </summary>
|
||||
public static class ScriptRootLoggerFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds the composed root script logger.
|
||||
/// </summary>
|
||||
/// <param name="publisher">
|
||||
/// The publisher the topic sink forwards entries to (the DPS publisher in production).
|
||||
/// </param>
|
||||
/// <param name="filePath">
|
||||
/// Path template for the rolling <c>scripts-*.log</c> file sink (e.g. <c>logs/scripts-.log</c>).
|
||||
/// </param>
|
||||
/// <param name="topicMinLevel">
|
||||
/// Minimum level for events forwarded to the <c>script-logs</c> topic; lower-level events
|
||||
/// still land in the file sink but are not pushed onto the cluster bus.
|
||||
/// </param>
|
||||
/// <returns>The composed root script logger.</returns>
|
||||
public static Serilog.ILogger Build(IScriptLogPublisher publisher, string filePath, LogEventLevel topicMinLevel)
|
||||
=> new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.WriteTo.File(filePath, rollingInterval: RollingInterval.Day)
|
||||
.WriteTo.Sink(new ScriptLogCompanionSink(Serilog.Log.Logger))
|
||||
.WriteTo.Sink(new ScriptLogTopicSink(publisher, topicMinLevel))
|
||||
.CreateLogger();
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using Akka.Actor;
|
||||
using Akka.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Clients;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components;
|
||||
@@ -11,14 +13,17 @@ using ZB.MOM.WW.OtOpcUa.Configuration;
|
||||
using ZB.MOM.WW.OtOpcUa.ControlPlane;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Engines;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Scripting;
|
||||
using ZB.MOM.WW.OtOpcUa.Host;
|
||||
using ZB.MOM.WW.OtOpcUa.Host.Configuration;
|
||||
using ZB.MOM.WW.OtOpcUa.Host.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.Host.Engines;
|
||||
using ZB.MOM.WW.OtOpcUa.Host.Health;
|
||||
using ZB.MOM.WW.OtOpcUa.Host.Logging;
|
||||
using ZB.MOM.WW.OtOpcUa.Host.Observability;
|
||||
using ZB.MOM.WW.OtOpcUa.Host.OpcUa;
|
||||
using ZB.MOM.WW.OtOpcUa.OpcUaServer;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Scripting;
|
||||
using ZB.MOM.WW.OtOpcUa.OpcUaServer.Security;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime;
|
||||
using ZB.MOM.WW.Auth.Abstractions.Roles;
|
||||
@@ -113,6 +118,21 @@ if (hasDriver)
|
||||
new RoslynScriptedAlarmEvaluator(sp.GetRequiredService<ILoggerFactory>().CreateLogger<RoslynScriptedAlarmEvaluator>()));
|
||||
builder.Services.AddSingleton<IScriptedAlarmEvaluator>(sp => sp.GetRequiredService<RoslynScriptedAlarmEvaluator>());
|
||||
|
||||
// Script-log fan-out (Layer 0). The DPS publisher resolves the ActorSystem lazily so it never
|
||||
// races Akka startup. ScriptRootLogger wraps the composed pipeline (rolling scripts-*.log +
|
||||
// error mirror to the main log + script-logs DPS topic) for unambiguous DI resolution; Task 3
|
||||
// injects it into the Roslyn evaluators above.
|
||||
var scriptLogFilePath = builder.Configuration["Scripting:LogFilePath"] ?? "logs/scripts-.log";
|
||||
var scriptLogTopicMinLevel = Enum.TryParse<LogEventLevel>(
|
||||
builder.Configuration["Scripting:LogTopicMinLevel"], ignoreCase: true, out var parsedLevel)
|
||||
? parsedLevel
|
||||
: LogEventLevel.Information;
|
||||
builder.Services.AddSingleton<IScriptLogPublisher>(sp =>
|
||||
new DpsScriptLogPublisher(() => sp.GetRequiredService<ActorSystem>()));
|
||||
builder.Services.AddSingleton(sp => new ScriptRootLogger(
|
||||
ScriptRootLoggerFactory.Build(
|
||||
sp.GetRequiredService<IScriptLogPublisher>(), scriptLogFilePath, scriptLogTopicMinLevel)));
|
||||
|
||||
builder.Services.AddValidatedOptions<LdapOptions, LdapOptionsValidator>(builder.Configuration, LdapOptions.SectionName);
|
||||
// TryAdd so a fused admin+driver node (where AddOtOpcUaAuth also registers these) ends up
|
||||
// with exactly one descriptor; on a driver-only node these are the sole registrations.
|
||||
|
||||
Reference in New Issue
Block a user