< Summary - Jellyfin

Information
Class: Jellyfin.Server.ServerSetupApp.StartupLogger
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/ServerSetupApp/StartupLogger.cs
Line coverage
88%
Covered lines: 30
Uncovered lines: 4
Coverable lines: 34
Total lines: 124
Line coverage: 88.2%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
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%
get_Topic()100%11100%
BeginGroup(...)100%11100%
With(...)100%11100%
With(...)100%210%
BeginGroup(...)100%11100%
AddToTopic(...)75%44100%
BeginScope(...)100%210%
IsEnabled(...)100%210%
Log(...)50%6691.66%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using Microsoft.Extensions.Logging;
 4using Microsoft.Extensions.Logging.Abstractions;
 5
 6namespace Jellyfin.Server.ServerSetupApp;
 7
 8/// <inheritdoc/>
 9public class StartupLogger : IStartupLogger
 10{
 11    private readonly StartupLogTopic? _topic;
 12
 13    /// <summary>
 14    /// Initializes a new instance of the <see cref="StartupLogger"/> class.
 15    /// </summary>
 16    /// <param name="logger">The underlying base logger.</param>
 17    public StartupLogger(ILogger logger)
 18    {
 180719        BaseLogger = logger;
 180720    }
 21
 22    /// <summary>
 23    /// Initializes a new instance of the <see cref="StartupLogger"/> class.
 24    /// </summary>
 25    /// <param name="logger">The underlying base logger.</param>
 26    /// <param name="topic">The group for this logger.</param>
 178527    internal StartupLogger(ILogger logger, StartupLogTopic? topic) : this(logger)
 28    {
 178529        _topic = topic;
 178530    }
 31
 132    internal static IStartupLogger Logger { get; set; } = new StartupLogger(NullLogger.Instance);
 33
 34    /// <inheritdoc/>
 718235    public StartupLogTopic? Topic => _topic;
 36
 37    /// <summary>
 38    /// Gets or Sets the underlying base logger.
 39    /// </summary>
 40    protected ILogger BaseLogger { get; set; }
 41
 42    /// <inheritdoc/>
 43    public IStartupLogger BeginGroup(FormattableString logEntry)
 44    {
 88245        return new StartupLogger(BaseLogger, AddToTopic(logEntry));
 46    }
 47
 48    /// <inheritdoc/>
 49    public IStartupLogger With(ILogger logger)
 50    {
 88251        return new StartupLogger(logger, Topic);
 52    }
 53
 54    /// <inheritdoc/>
 55    public IStartupLogger<TCategory> With<TCategory>(ILogger logger)
 56    {
 057        return new StartupLogger<TCategory>(logger, Topic);
 58    }
 59
 60    /// <inheritdoc/>
 61    public IStartupLogger<TCategory> BeginGroup<TCategory>(FormattableString logEntry)
 62    {
 2163        return new StartupLogger<TCategory>(BaseLogger, AddToTopic(logEntry));
 64    }
 65
 66    private StartupLogTopic AddToTopic(FormattableString logEntry)
 67    {
 90368        var startupEntry = new StartupLogTopic()
 90369        {
 90370            Content = logEntry.ToString(CultureInfo.InvariantCulture),
 90371            DateOfCreation = DateTimeOffset.Now
 90372        };
 73
 90374        if (Topic is null)
 75        {
 6376            SetupServer.LogQueue?.Enqueue(startupEntry);
 77        }
 78        else
 79        {
 84080            Topic.Children.Add(startupEntry);
 81        }
 82
 90383        return startupEntry;
 84    }
 85
 86    /// <inheritdoc/>
 87    public IDisposable? BeginScope<TState>(TState state)
 88        where TState : notnull
 89    {
 090        return null;
 91    }
 92
 93    /// <inheritdoc/>
 94    public bool IsEnabled(LogLevel logLevel)
 95    {
 096        return true;
 97    }
 98
 99    /// <inheritdoc/>
 100    public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Excepti
 101    {
 2226102        if (BaseLogger.IsEnabled(logLevel))
 103        {
 104            // if enabled allow the base logger also to receive the message
 588105            BaseLogger.Log(logLevel, eventId, state, exception, formatter);
 106        }
 107
 2226108        var startupEntry = new StartupLogTopic()
 2226109        {
 2226110            LogLevel = logLevel,
 2226111            Content = formatter(state, exception),
 2226112            DateOfCreation = DateTimeOffset.Now
 2226113        };
 114
 2226115        if (Topic is null)
 116        {
 0117            SetupServer.LogQueue?.Enqueue(startupEntry);
 118        }
 119        else
 120        {
 2226121            Topic.Children.Add(startupEntry);
 122        }
 2226123    }
 124}