< Summary - Jellyfin

Information
Class: Jellyfin.Server.ServerSetupApp.StartupLogger
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/ServerSetupApp/StartupLogger.cs
Line coverage
87%
Covered lines: 29
Uncovered lines: 4
Coverable lines: 33
Total lines: 102
Line coverage: 87.8%
Branch coverage
58%
Covered branches: 7
Total branches: 12
Branch coverage: 58.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
.ctor(...)100%11100%
.cctor()100%11100%
BeginGroup(...)75%44100%
BeginScope(...)100%210%
IsEnabled(...)100%210%
Log(...)50%8883.33%
With(...)100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Server/ServerSetupApp/StartupLogger.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4using System.Linq;
 5using Jellyfin.Server.Migrations.Routines;
 6using Microsoft.Extensions.Logging;
 7
 8namespace Jellyfin.Server.ServerSetupApp;
 9
 10/// <inheritdoc/>
 11public class StartupLogger : IStartupLogger
 12{
 13    private readonly SetupServer.StartupLogEntry? _groupEntry;
 14
 15    /// <summary>
 16    /// Initializes a new instance of the <see cref="StartupLogger"/> class.
 17    /// </summary>
 18    public StartupLogger()
 19    {
 170220        Loggers = [];
 170221    }
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="StartupLogger"/> class.
 25    /// </summary>
 170126    private StartupLogger(SetupServer.StartupLogEntry? groupEntry) : this()
 27    {
 170128        _groupEntry = groupEntry;
 170129    }
 30
 131    internal static IStartupLogger Logger { get; } = new StartupLogger();
 32
 33    private List<ILogger> Loggers { get; set; }
 34
 35    /// <inheritdoc/>
 36    public IStartupLogger BeginGroup(FormattableString logEntry)
 37    {
 86138        var startupEntry = new SetupServer.StartupLogEntry()
 86139        {
 86140            Content = logEntry.ToString(CultureInfo.InvariantCulture),
 86141            DateOfCreation = DateTimeOffset.Now
 86142        };
 43
 86144        if (_groupEntry is null)
 45        {
 2146            SetupServer.LogQueue?.Enqueue(startupEntry);
 47        }
 48        else
 49        {
 84050            _groupEntry.Children.Add(startupEntry);
 51        }
 52
 86153        return new StartupLogger(startupEntry);
 54    }
 55
 56    /// <inheritdoc/>
 57    public IDisposable? BeginScope<TState>(TState state)
 58        where TState : notnull
 59    {
 060        return null;
 61    }
 62
 63    /// <inheritdoc/>
 64    public bool IsEnabled(LogLevel logLevel)
 65    {
 066        return true;
 67    }
 68
 69    /// <inheritdoc/>
 70    public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Excepti
 71    {
 420072        foreach (var item in Loggers.Where(e => e.IsEnabled(logLevel)))
 73        {
 074            item.Log(logLevel, eventId, state, exception, formatter);
 75        }
 76
 210077        var startupEntry = new SetupServer.StartupLogEntry()
 210078        {
 210079            LogLevel = logLevel,
 210080            Content = formatter(state, exception),
 210081            DateOfCreation = DateTimeOffset.Now
 210082        };
 83
 210084        if (_groupEntry is null)
 85        {
 086            SetupServer.LogQueue?.Enqueue(startupEntry);
 87        }
 88        else
 89        {
 210090            _groupEntry.Children.Add(startupEntry);
 91        }
 210092    }
 93
 94    /// <inheritdoc/>
 95    public IStartupLogger With(ILogger logger)
 96    {
 84097        return new StartupLogger(_groupEntry)
 84098        {
 84099            Loggers = [.. Loggers, logger]
 840100        };
 101    }
 102}