feat(logs): log level, retention, size limits and rotation on server and desktop
Owner review 2, R11 asked for more log settings. The file sink now writes daily or hourly files, continues a full file in numbered parts and prunes by age and by the total size (never the file being written); its options change while it runs. Server: the file and console levels are separate and read by the logging filters at every line, so the admin panel's new Logs group applies without a restart; the engine's level follows the lower of the two. This also fixes a bug: the file logger was fixed at Information, so CHRONOS_LOG_LEVEL=Debug or Trace never reached the files. New variables CHRONOS_LOG_CONSOLE_LEVEL, CHRONOS_LOG_RETENTION_DAYS, CHRONOS_LOG_MAX_FILE_MB, CHRONOS_LOG_MAX_TOTAL_MB, CHRONOS_LOG_ROTATION, CHRONOS_AUDIT_RETENTION_DAYS and CHRONOS_DIAGNOSTICS_LOG_MB lock their settings like the others; the diagnostics zip keeps the configured share of each log. Desktop: Settings > Advanced gains Log level, Keep logs, File size, Logs total, Rotation and Diagnostics logs, applied at every save; Advanced's Reset section restores them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit cc875784e4952ee0e4c807b9d9c18496d3d5a8c3)
This commit is contained in:
1 parent
1f089888e8
commit
0e84392f4f
35 files changed
+1485
-119
No files matched your search
@@ -1,7 +1,8 @@
|
||||
// Settings (BRIEF §14.8): server name, ports, TLS, discovery, jobs, limits, language, retention. Values fixed by environment
|
||||
// variables are read-only here; ports, TLS, chunk size and job history apply at the next restart. Jobs run one at a time
|
||||
// (owner review 1): the parallelism (photos at once) and the priority queue apply at once. About (version, API, database,
|
||||
// uptime) is the last group, read-only (owner review 2); #/about opens here on it.
|
||||
// Settings (BRIEF §14.8): server name, ports, TLS, discovery, jobs, limits, language, retention, logs. Values fixed by
|
||||
// environment variables are read-only here; ports, TLS, chunk size and job history apply at the next restart. Jobs run one
|
||||
// at a time (owner review 1): the parallelism (photos at once) and the priority queue apply at once, as do the log levels,
|
||||
// retention, size limits and rotation (owner review 2, R11). About (version, API, database, uptime) is the last group,
|
||||
// read-only (owner review 2); #/about opens here on it.
|
||||
import { t, applyStrings, languages } from "../i18n.js";
|
||||
import { escapeHtml, attr, toast, errorText, nativeName, fingerprint, formatDuration, markInvalid, clearInvalid, invalidText, escapeReverts, routeParams, PROXY_WARNING } from "../ui.js";
|
||||
import { kindLabel } from "../jobs.js";
|
||||
@@ -10,10 +11,17 @@ import { kindLabel } from "../jobs.js";
|
||||
const VARIABLES = {
|
||||
serverName: "CHRONOS_SERVER_NAME", httpPort: "CHRONOS_HTTP_PORT", httpsPort: "CHRONOS_HTTPS_PORT", tlsMode: "CHRONOS_TLS_MODE",
|
||||
tlsCert: "CHRONOS_TLS_CERT", tlsKey: "CHRONOS_TLS_KEY", language: "CHRONOS_LANG", parallelism: "CHRONOS_PARALLELISM", discovery: "CHRONOS_DISCOVERY",
|
||||
priorityQueue: "CHRONOS_PRIORITY_QUEUE",
|
||||
priorityQueue: "CHRONOS_PRIORITY_QUEUE", logLevel: "CHRONOS_LOG_LEVEL", logRetentionDays: "CHRONOS_LOG_RETENTION_DAYS",
|
||||
logMaxFileMb: "CHRONOS_LOG_MAX_FILE_MB", logMaxTotalMb: "CHRONOS_LOG_MAX_TOTAL_MB", logRotation: "CHRONOS_LOG_ROTATION",
|
||||
auditRetentionDays: "CHRONOS_AUDIT_RETENTION_DAYS", diagnosticsLogMb: "CHRONOS_DIAGNOSTICS_LOG_MB",
|
||||
// CHRONOS_LOG_LEVEL sets the console's level too, unless CHRONOS_LOG_CONSOLE_LEVEL sets its own.
|
||||
consoleLogLevel: ["CHRONOS_LOG_CONSOLE_LEVEL", "CHRONOS_LOG_LEVEL"],
|
||||
};
|
||||
/** Levels of the priority queue, highest first. */
|
||||
const LEVELS = ["high", "normal", "low"];
|
||||
/** Log levels, least severe first (the server's wire names). */
|
||||
const LOG_LEVELS = ["trace", "debug", "information", "warning", "error", "critical", "none"];
|
||||
const ROTATIONS = ["daily", "hourly"];
|
||||
/** Settings the server names in error details whose field here has another name. */
|
||||
const FIELDS = { maxuploadbytes: "maxUploadMb", chunksizebytes: "chunkSizeMib" };
|
||||
const PEM_FILES = ["tlsCert", "tlsKey"];
|
||||
@@ -38,10 +46,15 @@ export async function render(root, { api, info, setMeta, actions }) {
|
||||
applyStrings(actions);
|
||||
|
||||
const locked = (name) => settings.locked.some((l) => l.toLowerCase() === name.toLowerCase());
|
||||
const lock = (name) => locked(name) ? `disabled title="${attr(t("Admin.Settings.Locked.Tip", VARIABLES[name] ?? name))}"` : `data-i18n-title="Admin.Settings.${cap(name)}.Tip"`;
|
||||
const lockedTip = (variable) => Array.isArray(variable) ? t("Admin.Settings.LockedEither.Tip", variable[0], variable[1]) : t("Admin.Settings.Locked.Tip", variable);
|
||||
const lock = (name) => locked(name) ? `disabled title="${attr(lockedTip(VARIABLES[name] ?? name))}"` : `data-i18n-title="Admin.Settings.${cap(name)}.Tip"`;
|
||||
const field = (name, input) => `<label class="field"><span data-i18n="Admin.Settings.${cap(name)}"></span>${input}</label>`;
|
||||
const number = (name, value, attrs = "") => field(name, `<input class="input narrow num" type="number" name="${name}" value="${attr(value)}" ${attrs} ${lock(name)}>`);
|
||||
const text = (name, value, attrs = "dir=\"auto\"") => field(name, `<input class="input" name="${name}" value="${attr(value ?? "")}" ${attrs} ${lock(name)}>`);
|
||||
// A value this page does not know stays listed, so saving the other settings never changes it.
|
||||
const choice = (name, value, values, label) => field(name, `<select class="input" name="${name}" ${lock(name)}>${values.concat(values.includes(value) ? [] : [value])
|
||||
.map((v) => `<option value="${attr(v)}" ${v === value ? "selected" : ""}>${escapeHtml(t(label(v)))}</option>`).join("")}</select>`);
|
||||
const level = (name, value) => choice(name, value, LOG_LEVELS, (l) => `Admin.Settings.Level.${cap(l)}`);
|
||||
|
||||
function draw() {
|
||||
root.innerHTML = `
|
||||
@@ -83,6 +96,17 @@ export async function render(root, { api, info, setMeta, actions }) {
|
||||
${number("uploadRetentionHours", settings.uploadRetentionHours, 'min="1" max="8760"')}
|
||||
${number("jobHistoryDays", settings.jobHistoryDays, 'min="1" max="3650"')}
|
||||
</section>
|
||||
<section class="panel" aria-labelledby="logs-title">
|
||||
<h2 id="logs-title" data-i18n="Admin.Settings.Logs"></h2>
|
||||
${level("logLevel", settings.logs.fileLevel)}
|
||||
${level("consoleLogLevel", settings.logs.consoleLevel)}
|
||||
${number("logRetentionDays", settings.logs.retentionDays, 'min="1" max="3650"')}
|
||||
${number("logMaxFileMb", settings.logs.maxFileMb, 'min="0" max="10240"')}
|
||||
${number("logMaxTotalMb", settings.logs.maxTotalMb, 'min="0" max="1048576"')}
|
||||
${choice("logRotation", settings.logs.rotation, ROTATIONS, (r) => `Admin.Settings.Rotation.${cap(r)}`)}
|
||||
${number("auditRetentionDays", settings.logs.auditRetentionDays, 'min="0" max="36500"')}
|
||||
${number("diagnosticsLogMb", settings.logs.diagnosticsLogMb, 'min="1" max="1024"')}
|
||||
</section>
|
||||
</form>
|
||||
${about()}`;
|
||||
applyStrings(root);
|
||||
@@ -157,6 +181,16 @@ export async function render(root, { api, info, setMeta, actions }) {
|
||||
tokenLifetimeDays: Number(data.get("tokenLifetimeDays")),
|
||||
uploadRetentionHours: Number(data.get("uploadRetentionHours")),
|
||||
jobHistoryDays: Number(data.get("jobHistoryDays")),
|
||||
logs: {
|
||||
fileLevel: String(value("logLevel", settings.logs.fileLevel)),
|
||||
consoleLevel: String(value("consoleLogLevel", settings.logs.consoleLevel)),
|
||||
retentionDays: Number(value("logRetentionDays", settings.logs.retentionDays)),
|
||||
maxFileMb: Number(value("logMaxFileMb", settings.logs.maxFileMb)),
|
||||
maxTotalMb: Number(value("logMaxTotalMb", settings.logs.maxTotalMb)),
|
||||
rotation: String(value("logRotation", settings.logs.rotation)),
|
||||
auditRetentionDays: Number(value("auditRetentionDays", settings.logs.auditRetentionDays)),
|
||||
diagnosticsLogMb: Number(value("diagnosticsLogMb", settings.logs.diagnosticsLogMb)),
|
||||
},
|
||||
};
|
||||
try {
|
||||
settings = await api.put("/api/v1/server/settings", request);
|
||||
|
||||
Reference in new issue
Block a user