fix(logs): apply log settings from the first line and name the locking variable
The desktop opened its log files with the default limits and wrote its first line, which prunes, before Settings › Advanced › Logs were applied. Every start, and every launch that only hands its file to the running Chronos, deleted logs older than 14 days and cut the folder to 1 GB whatever the user kept. AppLogging.Open now builds the sink from the stored settings before that line; the settings are read again once the launch owns the data folder. A total below one file deleted each finished file as the next one opened. The rule now lives in LogFileOptions.TotalBelowFile: the server keeps refusing it, the desktop raises the total to the file size and its rows no longer offer the combination. The desktop log rows threw on negative sizes from an imported or hand-edited file and showed raw values the files never got; they now show the applied ones. Upgraded Unraid and compose installs keep CHRONOS_LOG_LEVEL=Information, which locks both levels. The lock stays; the server now reports which variable fixes each locked setting (LockedBy), so the panel's tooltip names it exactly and says to remove it to change the value there. The releases README tells upgraders. The former-constructor log test no longer fails across midnight UTC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 8ba7162bd5926d34c5ec4e40e2a2dad063ee19c3)
This commit is contained in:
1 parent
8d66be709c
commit
ac121acf7c
53 files changed
+254
-92
No files matched your search
@@ -147,19 +147,28 @@ public sealed partial class LoggingTests(TestContext context)
|
||||
[Test]
|
||||
public async Task LevelsSetByTheEnvironmentAreLocked()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, o => o.Locked = [nameof(ServerOptions.LogLevel), nameof(ServerOptions.ConsoleLogLevel)]);
|
||||
// An install upgraded with the earlier compose file or Unraid template: CHRONOS_LOG_LEVEL fixes both levels.
|
||||
await using var server = await TestServer.StartAsync(context, o =>
|
||||
{
|
||||
o.Locked = [nameof(ServerOptions.LogLevel), nameof(ServerOptions.ConsoleLogLevel), nameof(ServerOptions.LogRotation)];
|
||||
o.LockedBy = new Dictionary<string, string> { [nameof(ServerOptions.LogLevel)] = "CHRONOS_LOG_LEVEL", [nameof(ServerOptions.ConsoleLogLevel)] = "CHRONOS_LOG_LEVEL" };
|
||||
});
|
||||
var admin = await server.AdminAsync();
|
||||
var settings = await SettingsAsync(admin);
|
||||
Assert.Contains("ConsoleLogLevel", settings.Locked);
|
||||
// The panel's tooltip names the variable that fixes each; one locked without it is named by the variable that would.
|
||||
string[] lockedBy = ["ConsoleLogLevel=CHRONOS_LOG_LEVEL", "LogLevel=CHRONOS_LOG_LEVEL", "LogRotation=CHRONOS_LOG_ROTATION"];
|
||||
Assert.SequenceEqual(lockedBy, settings.LockedBy.Select(l => $"{l.Key}={l.Value}").Order(StringComparer.Ordinal));
|
||||
var edited = settings with { HttpPort = 18080, HttpsPort = 18443 };
|
||||
using (var refused = await admin.PutAsJsonAsync("/api/v1/server/settings", edited with { Logs = edited.Logs with { ConsoleLevel = "debug" } },
|
||||
ProtocolJson.Default.ServerSettingsDto))
|
||||
Assert.Equal("ConsoleLogLevel", (await refused.ExpectErrorAsync(HttpStatusCode.Conflict, "setting_locked")).Details);
|
||||
Assert.Equal(LogLevel.Warning, server.Options.ConsoleLogLevel);
|
||||
// The settings no variable fixes still save.
|
||||
using (var saved = await admin.PutAsJsonAsync("/api/v1/server/settings", edited with { Logs = edited.Logs with { RetentionDays = 7 } },
|
||||
ProtocolJson.Default.ServerSettingsDto))
|
||||
await saved.ExpectAsync(HttpStatusCode.OK);
|
||||
// What a request says about the locks is ignored.
|
||||
using (var saved = await admin.PutAsJsonAsync("/api/v1/server/settings",
|
||||
edited with { Logs = edited.Logs with { RetentionDays = 7 }, LockedBy = new Dictionary<string, string>() }, ProtocolJson.Default.ServerSettingsDto))
|
||||
Assert.SequenceEqual(lockedBy, (await saved.ReadAsync(ProtocolJson.Default.ServerSettingsDto)).LockedBy.Select(l => $"{l.Key}={l.Value}").Order(StringComparer.Ordinal));
|
||||
Assert.Equal(7, server.Options.LogRetentionDays);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,8 @@ public sealed class StartupTests(TestContext context)
|
||||
["CHRONOS_DISCOVERY"] = "false",
|
||||
});
|
||||
Assert.SequenceEqual(["Database", "HttpPort", "Discovery"], options.Locked);
|
||||
// The admin panel names the variable that fixes each of them.
|
||||
Assert.Equal(("CHRONOS_DB", "CHRONOS_HTTP_PORT", "CHRONOS_DISCOVERY"), (options.LockedBy["Database"], options.LockedBy["HttpPort"], options.LockedBy["Discovery"]));
|
||||
Assert.Throws<InvalidOperationException>(() => ServerOptions.Load(new Dictionary<string, string?> { ["CHRONOS_DATA_PATH"] = root, ["CHRONOS_DB"] = "postgres", ["CHRONOS_WORKERS"] = "many" }));
|
||||
}
|
||||
|
||||
@@ -86,6 +88,7 @@ public sealed class StartupTests(TestContext context)
|
||||
var former = ServerOptions.Load(new Dictionary<string, string?> { ["CHRONOS_DATA_PATH"] = root, ["CHRONOS_DB"] = "postgres", ["CHRONOS_WORKERS"] = "5" });
|
||||
Assert.Equal((5, true), (former.Parallelism, former.FormerWorkersVariable));
|
||||
Assert.SequenceEqual(["Database", "Parallelism"], former.Locked);
|
||||
Assert.Equal("CHRONOS_WORKERS", former.LockedBy["Parallelism"]);
|
||||
var both = ServerOptions.Load(new Dictionary<string, string?>
|
||||
{
|
||||
["CHRONOS_DATA_PATH"] = root,
|
||||
@@ -96,6 +99,7 @@ public sealed class StartupTests(TestContext context)
|
||||
});
|
||||
Assert.Equal((7, true), (both.Parallelism, both.PriorityQueue));
|
||||
Assert.SequenceEqual(["Database", "Parallelism", "PriorityQueue"], both.Locked);
|
||||
Assert.Equal("CHRONOS_PARALLELISM", both.LockedBy["Parallelism"]);
|
||||
Assert.False(ServerOptions.Load(new Dictionary<string, string?> { ["CHRONOS_DATA_PATH"] = root, ["CHRONOS_DB"] = "postgres", ["CHRONOS_PARALLELISM"] = "2" })
|
||||
.FormerWorkersVariable);
|
||||
Assert.Throws<InvalidOperationException>(() => ServerOptions.Load(new Dictionary<string, string?> { ["CHRONOS_DATA_PATH"] = root, ["CHRONOS_DB"] = "postgres", ["CHRONOS_PRIORITY_QUEUE"] = "often" }));
|
||||
@@ -174,6 +178,8 @@ public sealed class StartupTests(TestContext context)
|
||||
var both = ServerOptions.Load(Env(("CHRONOS_LOG_LEVEL", "debug")));
|
||||
Assert.Equal((Microsoft.Extensions.Logging.LogLevel.Debug, Microsoft.Extensions.Logging.LogLevel.Debug), (both.LogLevel, both.ConsoleLogLevel));
|
||||
Assert.SequenceEqual(["Database", "LogLevel", "ConsoleLogLevel"], both.Locked);
|
||||
// The earlier compose file and Unraid template set CHRONOS_LOG_LEVEL: the panel names it on both levels.
|
||||
Assert.Equal(("CHRONOS_LOG_LEVEL", "CHRONOS_LOG_LEVEL"), (both.LockedBy["LogLevel"], both.LockedBy["ConsoleLogLevel"]));
|
||||
|
||||
var all = ServerOptions.Load(Env(("CHRONOS_LOG_LEVEL", "Trace"), ("CHRONOS_LOG_CONSOLE_LEVEL", "warn"), ("CHRONOS_LOG_RETENTION_DAYS", "30"),
|
||||
("CHRONOS_LOG_MAX_FILE_MB", "0"), ("CHRONOS_LOG_MAX_TOTAL_MB", "2048"), ("CHRONOS_LOG_ROTATION", "Hourly"), ("CHRONOS_AUDIT_RETENTION_DAYS", "365"),
|
||||
@@ -183,6 +189,7 @@ public sealed class StartupTests(TestContext context)
|
||||
Assert.Equal((Chronos.Core.Diagnostics.LogRotation.Hourly, 365, 16), (all.LogRotation, all.AuditRetentionDays, all.DiagnosticsLogMb));
|
||||
Assert.SequenceEqual(["Database", "LogLevel", "ConsoleLogLevel", "LogRetentionDays", "LogMaxFileMb", "LogMaxTotalMb", "LogRotation", "AuditRetentionDays",
|
||||
"DiagnosticsLogMb"], all.Locked);
|
||||
Assert.Equal(("CHRONOS_LOG_LEVEL", "CHRONOS_LOG_CONSOLE_LEVEL"), (all.LockedBy["LogLevel"], all.LockedBy["ConsoleLogLevel"]));
|
||||
|
||||
foreach (var invalid in new[]
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user