< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.Routines.CreateUserLoggingConfigFile
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/Routines/20250420060000_CreateUserLoggingConfigFile.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 28
Coverable lines: 28
Total lines: 78
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/4) Total lines: 7611/13/2026 - 12:19:51 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/4) Total lines: 78 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/4) Total lines: 7611/13/2026 - 12:19:51 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/4) Total lines: 78

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
PerformAsync(...)0%2040%
ExistingConfigUnmodified(...)100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/Routines/20250420060000_CreateUserLoggingConfigFile.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using System.Threading;
 6using System.Threading.Tasks;
 7using MediaBrowser.Common.Configuration;
 8using Newtonsoft.Json.Linq;
 9
 10namespace Jellyfin.Server.Migrations.Routines
 11{
 12    /// <summary>
 13    /// Migration to initialize the user logging configuration file "logging.user.json".
 14    /// If the deprecated logging.json file exists and has a custom config, it will be used as logging.user.json,
 15    /// otherwise a blank file will be created.
 16    /// </summary>
 17    [JellyfinMigration("2025-04-20T06:00:00", nameof(CreateUserLoggingConfigFile), "EF103419-8451-40D8-9F34-D1A8E93A1679
 18    internal class CreateUserLoggingConfigFile : IAsyncMigrationRoutine
 19    {
 20        /// <summary>
 21        /// File history for logging.json as existed during this migration creation. The contents for each has been mini
 22        /// </summary>
 023        private readonly List<string> _defaultConfigHistory = new List<string>
 024        {
 025            // 9a6c27947353585391e211aa88b925f81e8cd7b9
 026            @"{""Serilog"":{""MinimumLevel"":{""Default"":""Information"",""Override"":{""Microsoft"":""Warning"",""Syst
 027            // 71bdcd730705a714ee208eaad7290b7c68df3885
 028            @"{""Serilog"":{""MinimumLevel"":""Information"",""WriteTo"":[{""Name"":""Console"",""Args"":{""outputTempla
 029            // a44936f97f8afc2817d3491615a7cfe1e31c251c
 030            @"{""Serilog"":{""MinimumLevel"":""Information"",""WriteTo"":[{""Name"":""Console"",""Args"":{""outputTempla
 031            // 7af3754a11ad5a4284f107997fb5419a010ce6f3
 032            @"{""Serilog"":{""MinimumLevel"":""Information"",""WriteTo"":[{""Name"":""Console"",""Args"":{""outputTempla
 033            // 60691349a11f541958e0b2247c9abc13cb40c9fb
 034            @"{""Serilog"":{""MinimumLevel"":""Information"",""WriteTo"":[{""Name"":""Console"",""Args"":{""outputTempla
 035            // 65fe243afbcc4b596cf8726708c1965cd34b5f68
 036            @"{""Serilog"":{""MinimumLevel"":""Information"",""WriteTo"":[{""Name"":""Console"",""Args"":{""outputTempla
 037            // 96c9af590494aa8137d5a061aaf1e68feee60b67
 038            @"{""Serilog"":{""MinimumLevel"":""Information"",""WriteTo"":[{""Name"":""Console"",""Args"":{""outputTempla
 039        };
 40
 41        private readonly IApplicationPaths _appPaths;
 42
 43        public CreateUserLoggingConfigFile(IApplicationPaths appPaths)
 44        {
 045            _appPaths = appPaths;
 046        }
 47
 48        /// <inheritdoc/>
 49        public Task PerformAsync(CancellationToken cancellationToken)
 50        {
 051            var logDirectory = _appPaths.ConfigurationDirectoryPath;
 052            var existingConfigPath = Path.Combine(logDirectory, "logging.json");
 53
 54            // If the existing logging.json config file is unmodified, then 'reset' it by moving it to 'logging.old.json
 55            // NOTE: This config file has 'reloadOnChange: true', so this change will take effect immediately even thoug
 056            if (File.Exists(existingConfigPath) && ExistingConfigUnmodified(existingConfigPath))
 57            {
 058                File.Move(existingConfigPath, Path.Combine(logDirectory, "logging.old.json"));
 59            }
 60
 061            return Task.CompletedTask;
 62        }
 63
 64        /// <summary>
 65        /// Check if the existing logging.json file has not been modified by the user by comparing it to all the
 66        /// versions in our git history. Until now, the file has never been migrated after first creation so users
 67        /// could have any version from the git history.
 68        /// </summary>
 69        /// <exception cref="IOException"><paramref name="oldConfigPath"/> does not exist or could not be read.</excepti
 70        private bool ExistingConfigUnmodified(string oldConfigPath)
 71        {
 072            var existingConfigJson = JToken.Parse(File.ReadAllText(oldConfigPath));
 073            return _defaultConfigHistory
 074                .Select(JToken.Parse)
 075                .Any(historicalConfigJson => JToken.DeepEquals(existingConfigJson, historicalConfigJson));
 76        }
 77    }
 78}