fix: Log janitor updated to clean up logs in new 'cli' dir

pull/201/head
Robert Dailey 2 years ago
parent 7d54708375
commit a22d6dec33

@ -1,6 +1,6 @@
using System.IO.Abstractions; using System.IO.Abstractions;
using MoreLinq.Extensions;
using Recyclarr.Cli.Logging; using Recyclarr.Cli.Logging;
using Recyclarr.TestLibrary;
using Recyclarr.TestLibrary.AutoFixture; using Recyclarr.TestLibrary.AutoFixture;
using Recyclarr.TrashLib.TestLibrary; using Recyclarr.TrashLib.TestLibrary;
@ -18,13 +18,18 @@ public class LogJanitorTest
{ {
var testFiles = new[] var testFiles = new[]
{ {
paths.LogDirectory.File("trash_2021-05-15_19-00-00.log"), "trash_2021-05-15_19-00-00.log",
paths.LogDirectory.File("trash_2021-05-15_20-00-00.log"), "trash_2021-05-15_20-00-00.log",
paths.LogDirectory.File("trash_2021-05-15_21-00-00.log"), "trash_2021-05-15_21-00-00.log",
paths.LogDirectory.File("trash_2021-05-15_22-00-00.log") "trash_2021-05-15_22-00-00.log"
}; }
.Select(x => paths.LogDirectory.File(x))
.ToList();
testFiles.ForEach(x => fs.AddFile(x.FullName, new MockFileData(""))); foreach (var file in testFiles)
{
fs.AddEmptyFile(file);
}
janitor.DeleteOldestLogFiles(2); janitor.DeleteOldestLogFiles(2);

@ -1,5 +1,4 @@
using System.IO.Abstractions; using System.IO.Abstractions;
using Recyclarr.Common.Extensions;
using Recyclarr.Common.Serilog; using Recyclarr.Common.Serilog;
using Recyclarr.TrashLib; using Recyclarr.TrashLib;
using Recyclarr.TrashLib.Startup; using Recyclarr.TrashLib.Startup;
@ -49,7 +48,7 @@ public class LoggerFactory
public ILogger Create() public ILogger Create()
{ {
var logFilePrefix = $"recyclarr_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}"; var logFilePrefix = $"recyclarr_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}";
var logDir = _paths.LogDirectory.SubDir("cli"); var logDir = _paths.LogDirectory;
string LogFilePath(string type) string LogFilePath(string type)
{ {

@ -1,4 +1,5 @@
using System.IO.Abstractions; using System.IO.Abstractions;
using Recyclarr.Common.Extensions;
using Recyclarr.TrashLib.Startup; using Recyclarr.TrashLib.Startup;
namespace Recyclarr.TrashLib; namespace Recyclarr.TrashLib;
@ -18,8 +19,8 @@ public class AppPaths : IAppPaths
public IFileInfo ConfigPath => AppDataDirectory.File(DefaultConfigFilename); public IFileInfo ConfigPath => AppDataDirectory.File(DefaultConfigFilename);
public IFileInfo SettingsPath => AppDataDirectory.File("settings.yml"); public IFileInfo SettingsPath => AppDataDirectory.File("settings.yml");
public IFileInfo SecretsPath => AppDataDirectory.File("secrets.yml"); public IFileInfo SecretsPath => AppDataDirectory.File("secrets.yml");
public IDirectoryInfo LogDirectory => AppDataDirectory.SubDirectory("logs"); public IDirectoryInfo LogDirectory => AppDataDirectory.SubDir("logs", "cli");
public IDirectoryInfo RepoDirectory => AppDataDirectory.SubDirectory("repo"); public IDirectoryInfo RepoDirectory => AppDataDirectory.SubDir("repo");
public IDirectoryInfo CacheDirectory => AppDataDirectory.SubDirectory("cache"); public IDirectoryInfo CacheDirectory => AppDataDirectory.SubDir("cache");
public IDirectoryInfo ConfigsDirectory => AppDataDirectory.SubDirectory("configs"); public IDirectoryInfo ConfigsDirectory => AppDataDirectory.SubDir("configs");
} }

Loading…
Cancel
Save