From 75efe9cf0a15b6871726a4c2e8802e2af88cf1d1 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Tue, 1 Jan 2019 16:27:11 +0100 Subject: Rename and rework entry point --- .../EnvironmentInfo/EnvironmentInfo.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'Emby.Server.Implementations/EnvironmentInfo') diff --git a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs index 7655051095..ad941de550 100644 --- a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs +++ b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs @@ -1,12 +1,12 @@ using System; using System.IO; using MediaBrowser.Model.System; +using System.Runtime.InteropServices; namespace Emby.Server.Implementations.EnvironmentInfo { public class EnvironmentInfo : IEnvironmentInfo { - private Architecture? _customArchitecture; private MediaBrowser.Model.System.OperatingSystem? _customOperatingSystem; public virtual MediaBrowser.Model.System.OperatingSystem OperatingSystem @@ -60,22 +60,7 @@ namespace Emby.Server.Implementations.EnvironmentInfo } } - public Architecture SystemArchitecture - { - get - { - if (_customArchitecture.HasValue) - { - return _customArchitecture.Value; - } - - return Environment.Is64BitOperatingSystem ? MediaBrowser.Model.System.Architecture.X64 : MediaBrowser.Model.System.Architecture.X86; - } - set - { - _customArchitecture = value; - } - } + public Architecture SystemArchitecture { get; set; } public string GetEnvironmentVariable(string name) { -- cgit v1.2.3 From a44936f97f8afc2817d3491615a7cfe1e31c251c Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Tue, 1 Jan 2019 18:41:02 +0100 Subject: Fix and improve logging --- Emby.Server.Implementations/ApplicationHost.cs | 62 +++++++--------------- .../EnvironmentInfo/EnvironmentInfo.cs | 10 +++- Jellyfin.Server/Jellyfin.Server.csproj | 4 ++ Jellyfin.Server/Program.cs | 8 +-- .../Resources/Configuration/logging.json | 19 +++++++ 5 files changed, 57 insertions(+), 46 deletions(-) create mode 100644 Jellyfin.Server/Resources/Configuration/logging.json (limited to 'Emby.Server.Implementations/EnvironmentInfo') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 060898684e..09179c15ea 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(); - - 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; + .Distinct(); + + 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 ad941de550..5cff2dff09 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 cf83967855..09491d6a53 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 b768e10323..dd5e427df2 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 0000000000..78f99b2ad9 --- /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}" + } + } + ] + } +} -- cgit v1.2.3 From cf7e36561037e0e3c0d532b7a0c8d7d668c2373b Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 2 Jan 2019 00:21:06 +0100 Subject: Fix inconsistent code style --- Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs | 3 ++- Jellyfin.Server/Program.cs | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'Emby.Server.Implementations/EnvironmentInfo') diff --git a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs index 5cff2dff09..985eb71da9 100644 --- a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs +++ b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs @@ -41,7 +41,8 @@ namespace Emby.Server.Implementations.EnvironmentInfo { get { - switch (OperatingSystem) { + 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"; diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index a477d8b5ad..f0907fd581 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -120,7 +120,8 @@ namespace Jellyfin.Server // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. programDataPath = Environment.GetEnvironmentVariable("XDG_DATA_HOME"); // If $XDG_DATA_HOME is either not set or empty, $HOME/.local/share should be used. - if (string.IsNullOrEmpty(programDataPath)){ + if (string.IsNullOrEmpty(programDataPath)) + { programDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); } } @@ -128,7 +129,8 @@ namespace Jellyfin.Server } string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); - if (string.IsNullOrEmpty(logDir)){ + if (string.IsNullOrEmpty(logDir)) + { logDir = Path.Combine(programDataPath, "logs"); // Ensure logDir exists Directory.CreateDirectory(logDir); -- cgit v1.2.3 From 6643ac3ea412ea62fc067ae6b24ddfe69fd18482 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 2 Jan 2019 00:41:47 +0100 Subject: Clean up EnvironmentInfo --- .../EnvironmentInfo/EnvironmentInfo.cs | 32 ++++------------------ Jellyfin.Server/Program.cs | 9 +----- 2 files changed, 6 insertions(+), 35 deletions(-) (limited to 'Emby.Server.Implementations/EnvironmentInfo') diff --git a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs index 985eb71da9..03e10e7ea3 100644 --- a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs +++ b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs @@ -8,35 +8,13 @@ namespace Emby.Server.Implementations.EnvironmentInfo // TODO: Rework @bond public class EnvironmentInfo : IEnvironmentInfo { - private MediaBrowser.Model.System.OperatingSystem? _customOperatingSystem; - - public virtual MediaBrowser.Model.System.OperatingSystem OperatingSystem + public EnvironmentInfo(MediaBrowser.Model.System.OperatingSystem operatingSystem) { - get - { - if (_customOperatingSystem.HasValue) - { - return _customOperatingSystem.Value; - } - - switch (Environment.OSVersion.Platform) - { - case PlatformID.MacOSX: - return MediaBrowser.Model.System.OperatingSystem.OSX; - case PlatformID.Win32NT: - return MediaBrowser.Model.System.OperatingSystem.Windows; - case PlatformID.Unix: - return MediaBrowser.Model.System.OperatingSystem.Linux; - } - - return MediaBrowser.Model.System.OperatingSystem.Windows; - } - set - { - _customOperatingSystem = value; - } + OperatingSystem = operatingSystem; } + public MediaBrowser.Model.System.OperatingSystem OperatingSystem { get; private set; } + public string OperatingSystemName { get @@ -69,7 +47,7 @@ namespace Emby.Server.Implementations.EnvironmentInfo } } - public Architecture SystemArchitecture { get; set; } + public Architecture SystemArchitecture { get { return RuntimeInformation.OSArchitecture; } } public string GetEnvironmentVariable(string name) { diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index f0907fd581..0150cd5337 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -57,7 +57,7 @@ namespace Jellyfin.Server _logger.LogInformation("Jellyfin version: {Version}", version); - EnvironmentInfo environmentInfo = getEnvironmentInfo(); + EnvironmentInfo environmentInfo = new EnvironmentInfo(getOperatingSystem()); ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo); SQLitePCL.Batteries_V2.Init(); @@ -220,13 +220,6 @@ namespace Jellyfin.Server return new NullImageEncoder(); } - private static EnvironmentInfo getEnvironmentInfo() - => new EnvironmentInfo() - { - SystemArchitecture = RuntimeInformation.OSArchitecture, - OperatingSystem = getOperatingSystem() - }; - private static MediaBrowser.Model.System.OperatingSystem getOperatingSystem() { switch (Environment.OSVersion.Platform) { -- cgit v1.2.3