diff --git a/CHANGELOG.md b/CHANGELOG.md index b016e34b..1a7dd6f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Log files are restructured. They are now under `logs/cli`. +- Log files are split. There is now a `verbose.log` and `debug.log` for every run. The time stamps + between the two will be identical. + ## [4.3.0] - 2023-01-22 ### Added diff --git a/src/Recyclarr.Cli/Logging/LoggerFactory.cs b/src/Recyclarr.Cli/Logging/LoggerFactory.cs index 544806e3..22ce25b4 100644 --- a/src/Recyclarr.Cli/Logging/LoggerFactory.cs +++ b/src/Recyclarr.Cli/Logging/LoggerFactory.cs @@ -1,4 +1,5 @@ using System.IO.Abstractions; +using Recyclarr.Common.Extensions; using Recyclarr.Common.Serilog; using Recyclarr.TrashLib; using Recyclarr.TrashLib.Startup; @@ -47,13 +48,24 @@ public class LoggerFactory public ILogger Create() { - var logPath = _paths.LogDirectory.File($"trash_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.log"); + var logFilePrefix = $"recyclarr_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}"; + var logDir = _paths.LogDirectory.SubDir("cli"); + + string LogFilePath(string type) + { + return logDir.File($"{logFilePrefix}.{type}.log").FullName; + } return new LoggerConfiguration() - .MinimumLevel.Is(LogEventLevel.Debug) + .MinimumLevel.Is(LogEventLevel.Verbose) .Enrich.With() .WriteTo.Console(GetConsoleTemplate(), levelSwitch: _levelSwitch) - .WriteTo.File(GetFileTemplate(), logPath.FullName) + .WriteTo.Logger(c => c + .MinimumLevel.Debug() + .WriteTo.File(GetFileTemplate(), LogFilePath("debug"))) + .WriteTo.Logger(c => c + .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Verbose) + .WriteTo.File(GetFileTemplate(), LogFilePath("verbose"))) .Enrich.FromLogContext() .CreateLogger(); } diff --git a/src/Recyclarr.Common/Extensions/FileSystemExtensions.cs b/src/Recyclarr.Common/Extensions/FileSystemExtensions.cs index f4b128f8..897e27ca 100644 --- a/src/Recyclarr.Common/Extensions/FileSystemExtensions.cs +++ b/src/Recyclarr.Common/Extensions/FileSystemExtensions.cs @@ -62,4 +62,10 @@ public static class FileSystemExtensions { return Regex.Replace(path, $"^{Regex.Escape(oldDir)}", newDir); } + + public static IDirectoryInfo SubDir(this IDirectoryInfo dir, params string[] subdirectories) + { + return subdirectories.Aggregate(dir, + (d, s) => d.FileSystem.DirectoryInfo.New(d.FileSystem.Path.Combine(d.FullName, s))); + } } diff --git a/src/Recyclarr.TrashLib/Http/FlurlLogging.cs b/src/Recyclarr.TrashLib/Http/FlurlLogging.cs index 500b0a01..322674f3 100644 --- a/src/Recyclarr.TrashLib/Http/FlurlLogging.cs +++ b/src/Recyclarr.TrashLib/Http/FlurlLogging.cs @@ -14,7 +14,7 @@ public static class FlurlLogging { var url = urlInterceptor(call.Request.Url.Clone()); log.Debug("HTTP Request: {Method} {Url}", call.HttpRequestMessage.Method, url); - LogBody(log, call.RequestBody); + LogBody(log, url, call.RequestBody); }; settings.AfterCallAsync = async call => @@ -26,7 +26,7 @@ public static class FlurlLogging var content = call.Response?.ResponseMessage.Content; if (content is not null) { - LogBody(log, await content.ReadAsStringAsync()); + LogBody(log, url, await content.ReadAsStringAsync()); } }; @@ -42,7 +42,7 @@ public static class FlurlLogging }; } - private static void LogBody(ILogger log, string? body) + private static void LogBody(ILogger log, Url url, string? body) { if (body is null) { @@ -50,7 +50,7 @@ public static class FlurlLogging } body = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(body)); - log.Debug("HTTP Body: {Body}", body); + log.Verbose("HTTP Body: {Url} {Body}", url, body); } public static Url SanitizeUrl(Url url)