From 5a6a16e7dc1d4e0cd31cff358619f7db60c866eb Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Mon, 15 Nov 2021 13:42:19 +0100 Subject: [PATCH] Upgrade Loki sink to 4.0.0-beta3. This fixes many bugs with it. --- Robust.Server/BaseServer.cs | 17 +++++++----- Robust.Server/Log/LokiLogHandler.cs | 40 ++++++++++++++++------------- Robust.Server/Robust.Server.csproj | 2 +- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Robust.Server/BaseServer.cs b/Robust.Server/BaseServer.cs index f9c90d241..1c6bf90e7 100644 --- a/Robust.Server/BaseServer.cs +++ b/Robust.Server/BaseServer.cs @@ -424,12 +424,12 @@ namespace Robust.Server return false; } - LokiCredentials credentials; - if (string.IsNullOrWhiteSpace(username)) + LokiSinkConfiguration cfg = new() { - credentials = new NoAuthCredentials(address); - } - else + LokiUrl = address + }; + + if (!string.IsNullOrWhiteSpace(username)) { if (string.IsNullOrWhiteSpace(password)) { @@ -437,13 +437,16 @@ namespace Robust.Server return false; } - credentials = new BasicAuthCredentials(address, username, password); + cfg.LokiUsername = username; + cfg.LokiPassword = password; } + cfg.LogLabelProvider = new LogLabelProvider(serverName); + Logger.DebugS("loki", "Loki enabled for server {ServerName} loki address {LokiAddress}.", serverName, address); - var handler = new LokiLogHandler(serverName, credentials); + var handler = new LokiLogHandler(cfg); _log.RootSawmill.AddHandler(handler); return true; } diff --git a/Robust.Server/Log/LokiLogHandler.cs b/Robust.Server/Log/LokiLogHandler.cs index e144d13b4..5b6614253 100644 --- a/Robust.Server/Log/LokiLogHandler.cs +++ b/Robust.Server/Log/LokiLogHandler.cs @@ -13,10 +13,10 @@ namespace Robust.Server.Log { private readonly SLogger _sLogger; - public LokiLogHandler(string serverName, LokiCredentials credentials) + public LokiLogHandler(LokiSinkConfiguration configuration) { _sLogger = new LoggerConfiguration() - .WriteTo.LokiHttp(credentials, new LogLabelProvider(serverName)) + .WriteTo.LokiHttp(() => configuration) .MinimumLevel.Debug() .CreateLogger(); } @@ -37,24 +37,28 @@ namespace Robust.Server.Log { _sLogger.Dispose(); } + } - private sealed class LogLabelProvider : ILogLabelProvider + public sealed class LogLabelProvider : ILogLabelProvider + { + private readonly string _serverName; + + public LogLabelProvider(string serverName) { - private readonly string _serverName; - - public LogLabelProvider(string serverName) - { - _serverName = serverName; - } - - public IList GetLabels() - { - return new[] - { - new LokiLabel("App", "Robust.Server"), - new LokiLabel("Server", _serverName), - }; - } + _serverName = serverName; } + + public IList GetLabels() + { + return new[] + { + new LokiLabel("App", "Robust.Server"), + new LokiLabel("Server", _serverName), + }; + } + + public IList PropertiesAsLabels => Array.Empty(); + public IList PropertiesToAppend => Array.Empty(); + public LokiFormatterStrategy FormatterStrategy => LokiFormatterStrategy.SpecificPropertiesAsLabelsAndRestAppended; } } diff --git a/Robust.Server/Robust.Server.csproj b/Robust.Server/Robust.Server.csproj index 3d4c3ec67..0323bb9f2 100644 --- a/Robust.Server/Robust.Server.csproj +++ b/Robust.Server/Robust.Server.csproj @@ -15,7 +15,7 @@ - +