feat: Split and restructure CLI logs

pull/201/head
Robert Dailey 1 year ago
parent 5adb966aa9
commit c0bad938d7

@ -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

@ -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<ExceptionMessageEnricher>()
.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();
}

@ -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)));
}
}

@ -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)

Loading…
Cancel
Save