aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/ServerSetupApp/StartupLogger.cs
diff options
context:
space:
mode:
authorJPVenson <github@jpb.email>2025-06-05 17:59:11 +0300
committerGitHub <noreply@github.com>2025-06-05 08:59:11 -0600
commit88332e89c458266bc073d3304eafcb23603f15fa (patch)
treef067cdc997219a1a15e11356ef7aa31b466d7bba /Jellyfin.Server/ServerSetupApp/StartupLogger.cs
parenta3578caa8c71c84b278e18a07ebc157bcf04c687 (diff)
Feature/version check in library migration (#14105)
Diffstat (limited to 'Jellyfin.Server/ServerSetupApp/StartupLogger.cs')
-rw-r--r--Jellyfin.Server/ServerSetupApp/StartupLogger.cs102
1 files changed, 102 insertions, 0 deletions
diff --git a/Jellyfin.Server/ServerSetupApp/StartupLogger.cs b/Jellyfin.Server/ServerSetupApp/StartupLogger.cs
new file mode 100644
index 000000000..2b86dc0c1
--- /dev/null
+++ b/Jellyfin.Server/ServerSetupApp/StartupLogger.cs
@@ -0,0 +1,102 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using Jellyfin.Server.Migrations.Routines;
+using Microsoft.Extensions.Logging;
+
+namespace Jellyfin.Server.ServerSetupApp;
+
+/// <inheritdoc/>
+public class StartupLogger : IStartupLogger
+{
+ private readonly SetupServer.StartupLogEntry? _groupEntry;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="StartupLogger"/> class.
+ /// </summary>
+ public StartupLogger()
+ {
+ Loggers = [];
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="StartupLogger"/> class.
+ /// </summary>
+ private StartupLogger(SetupServer.StartupLogEntry? groupEntry) : this()
+ {
+ _groupEntry = groupEntry;
+ }
+
+ internal static IStartupLogger Logger { get; } = new StartupLogger();
+
+ private List<ILogger> Loggers { get; set; }
+
+ /// <inheritdoc/>
+ public IStartupLogger BeginGroup(FormattableString logEntry)
+ {
+ var startupEntry = new SetupServer.StartupLogEntry()
+ {
+ Content = logEntry.ToString(CultureInfo.InvariantCulture),
+ DateOfCreation = DateTimeOffset.Now
+ };
+
+ if (_groupEntry is null)
+ {
+ SetupServer.LogQueue?.Enqueue(startupEntry);
+ }
+ else
+ {
+ _groupEntry.Children.Add(startupEntry);
+ }
+
+ return new StartupLogger(startupEntry);
+ }
+
+ /// <inheritdoc/>
+ public IDisposable? BeginScope<TState>(TState state)
+ where TState : notnull
+ {
+ return null;
+ }
+
+ /// <inheritdoc/>
+ public bool IsEnabled(LogLevel logLevel)
+ {
+ return true;
+ }
+
+ /// <inheritdoc/>
+ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
+ {
+ foreach (var item in Loggers.Where(e => e.IsEnabled(logLevel)))
+ {
+ item.Log(logLevel, eventId, state, exception, formatter);
+ }
+
+ var startupEntry = new SetupServer.StartupLogEntry()
+ {
+ LogLevel = logLevel,
+ Content = formatter(state, exception),
+ DateOfCreation = DateTimeOffset.Now
+ };
+
+ if (_groupEntry is null)
+ {
+ SetupServer.LogQueue?.Enqueue(startupEntry);
+ }
+ else
+ {
+ _groupEntry.Children.Add(startupEntry);
+ }
+ }
+
+ /// <inheritdoc/>
+ public IStartupLogger With(ILogger logger)
+ {
+ return new StartupLogger(_groupEntry)
+ {
+ Loggers = [.. Loggers, logger]
+ };
+ }
+}