From a44936f97f8afc2817d3491615a7cfe1e31c251c Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Tue, 1 Jan 2019 18:41:02 +0100 Subject: [PATCH] Fix and improve logging --- .../ApplicationHost.cs | 60 ++++++------------- .../EnvironmentInfo/EnvironmentInfo.cs | 10 +++- Jellyfin.Server/Jellyfin.Server.csproj | 4 ++ Jellyfin.Server/Program.cs | 8 ++- .../Resources/Configuration/logging.json | 19 ++++++ 5 files changed, 56 insertions(+), 45 deletions(-) create mode 100644 Jellyfin.Server/Resources/Configuration/logging.json diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 060898684..09179c15e 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -799,27 +799,6 @@ namespace Emby.Server.Implementations JsonSerializer = CreateJsonSerializer(); - OnLoggerLoaded(true); - //LoggerFactory.LoggerLoaded += (s, e) => OnLoggerLoaded(false); - - DiscoverTypes(); - - SetHttpLimit(); - - RegisterResources(); - - FindParts(); - } - - protected virtual void OnLoggerLoaded(bool isFirstLoad) - { - Logger.LogInformation("Application version: {0}", ApplicationVersion); - - if (!isFirstLoad) - { - LogEnvironmentInfo(Logger, ApplicationPaths, false); - } - if (Plugins != null) { var pluginBuilder = new StringBuilder(); @@ -831,6 +810,14 @@ namespace Emby.Server.Implementations Logger.LogInformation("Plugins: {plugins}", pluginBuilder.ToString()); } + + DiscoverTypes(); + + SetHttpLimit(); + + RegisterResources(); + + FindParts(); } protected virtual IHttpClient CreateHttpClient() @@ -1073,36 +1060,27 @@ namespace Emby.Server.Implementations { get { - return "netframework"; + return "netcore"; } } - public static void LogEnvironmentInfo(ILogger Logger, IApplicationPaths appPaths, bool isStartup) - { - Logger.LogInformation("Jellyfin:\n{ex}", GetBaseExceptionMessage(appPaths).ToString()); - } - - protected static StringBuilder GetBaseExceptionMessage(IApplicationPaths appPaths) + public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths, EnvironmentInfo.EnvironmentInfo environmentInfo) { var builder = new StringBuilder(); // Distinct these to prevent users from reporting problems that aren't actually problems var commandLineArgs = Environment .GetCommandLineArgs() - .Distinct() - .ToArray(); + .Distinct(); - builder.AppendLine(string.Format("Command line: {0}", string.Join(" ", commandLineArgs))); - - builder.AppendLine(string.Format("Operating system: {0}", Environment.OSVersion)); - builder.AppendLine(string.Format("64-Bit OS: {0}", Environment.Is64BitOperatingSystem)); - builder.AppendLine(string.Format("64-Bit Process: {0}", Environment.Is64BitProcess)); - builder.AppendLine(string.Format("User Interactive: {0}", Environment.UserInteractive)); - builder.AppendLine(string.Format("Processor count: {0}", Environment.ProcessorCount)); - builder.AppendLine(string.Format("Program data path: {0}", appPaths.ProgramDataPath)); - builder.AppendLine(string.Format("Application directory: {0}", appPaths.ProgramSystemPath)); - - return builder; + logger.LogInformation("Arguments: {Args}", commandLineArgs); + logger.LogInformation("Operating system: {OS} {OSVersion}", environmentInfo.OperatingSystemName, environmentInfo.OperatingSystemVersion); + logger.LogInformation("Architecture: {Architecture}", environmentInfo.SystemArchitecture); + logger.LogInformation("64-Bit Process: {0}", Environment.Is64BitProcess); + logger.LogInformation("User Interactive: {0}", Environment.UserInteractive); + logger.LogInformation("Processor count: {0}", Environment.ProcessorCount); + logger.LogInformation("Program data path: {0}", appPaths.ProgramDataPath); + logger.LogInformation("Application directory: {0}", appPaths.ProgramSystemPath); } private void SetHttpLimit() diff --git a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs index ad941de55..5cff2dff0 100644 --- a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs +++ b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs @@ -5,6 +5,7 @@ using System.Runtime.InteropServices; namespace Emby.Server.Implementations.EnvironmentInfo { + // TODO: Rework @bond public class EnvironmentInfo : IEnvironmentInfo { private MediaBrowser.Model.System.OperatingSystem? _customOperatingSystem; @@ -40,7 +41,14 @@ namespace Emby.Server.Implementations.EnvironmentInfo { get { - return Environment.OSVersion.Platform.ToString(); + switch (OperatingSystem) { + case MediaBrowser.Model.System.OperatingSystem.Android: return "Android"; + case MediaBrowser.Model.System.OperatingSystem.BSD: return "BSD"; + case MediaBrowser.Model.System.OperatingSystem.Linux: return "Linux"; + case MediaBrowser.Model.System.OperatingSystem.OSX: return "macOS"; + case MediaBrowser.Model.System.OperatingSystem.Windows: return "Windows"; + default: throw new Exception($"Unknown OS {OperatingSystem}"); + } } } diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj index cf8396785..09491d6a5 100644 --- a/Jellyfin.Server/Jellyfin.Server.csproj +++ b/Jellyfin.Server/Jellyfin.Server.csproj @@ -15,6 +15,10 @@ + + + + diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index b768e1032..dd5e427df 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -59,14 +59,16 @@ namespace Jellyfin.Server AppDomain.CurrentDomain.UnhandledException += (sender, e) => _logger.LogCritical((Exception)e.ExceptionObject, "Unhandled Exception");; - ApplicationHost.LogEnvironmentInfo(_logger, appPaths, true); + _logger.LogInformation("Jellyfin version: {Version}", entryAssembly.GetName().Version); + + EnvironmentInfo environmentInfo = getEnvironmentInfo(); + ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo); SQLitePCL.Batteries_V2.Init(); // Allow all https requests ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; }); - EnvironmentInfo environmentInfo = getEnvironmentInfo(); var fileSystem = new ManagedFileSystem(_loggerFactory.CreateLogger("FileSystem"), environmentInfo, null, appPaths.TempDirectory, true); using (var appHost = new CoreAppHost( @@ -144,7 +146,7 @@ namespace Jellyfin.Server { // For some reason the csproj name is used instead of the assembly name using (Stream rscstr = typeof(Program).Assembly - .GetManifestResourceStream("EmbyServer.Resources.Configuration.logging.json")) + .GetManifestResourceStream("Jellyfin.Server.Resources.Configuration.logging.json")) using (Stream fstr = File.Open(path, FileMode.CreateNew)) { await rscstr.CopyToAsync(fstr); diff --git a/Jellyfin.Server/Resources/Configuration/logging.json b/Jellyfin.Server/Resources/Configuration/logging.json new file mode 100644 index 000000000..78f99b2ad --- /dev/null +++ b/Jellyfin.Server/Resources/Configuration/logging.json @@ -0,0 +1,19 @@ +{ + "Serilog": { + "MinimumLevel": "Information", + "WriteTo": [ + { "Name": "Console", + "Args": { + "outputTemplate": "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}" + } + }, + { "Name": "File", + "Args": { + "path": "%JELLYFIN_LOG_DIR%//log_.log", + "rollingInterval": "Day", + "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}" + } + } + ] + } +}