chore(logs): rotate daily and prune after 24h
This commit is contained in:
@@ -7,7 +7,11 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { setVerbose } from "./globals.js";
|
||||
import { logDebug, logError, logInfo, logSuccess, logWarn } from "./logger.js";
|
||||
import { resetLogger, setLoggerOverride } from "./logging.js";
|
||||
import {
|
||||
DEFAULT_LOG_DIR,
|
||||
resetLogger,
|
||||
setLoggerOverride,
|
||||
} from "./logging.js";
|
||||
import type { RuntimeEnv } from "./runtime.js";
|
||||
|
||||
describe("logger helpers", () => {
|
||||
@@ -67,6 +71,28 @@ describe("logger helpers", () => {
|
||||
expect(content).toContain("warn-only");
|
||||
cleanup(logPath);
|
||||
});
|
||||
|
||||
it("uses daily rolling default log file and prunes old ones", () => {
|
||||
resetLogger();
|
||||
setLoggerOverride({}); // force defaults regardless of user config
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const todayPath = path.join(DEFAULT_LOG_DIR, `warelay-${today}.log`);
|
||||
|
||||
// create an old file to be pruned
|
||||
const oldPath = path.join(DEFAULT_LOG_DIR, "warelay-2000-01-01.log");
|
||||
fs.mkdirSync(DEFAULT_LOG_DIR, { recursive: true });
|
||||
fs.writeFileSync(oldPath, "old");
|
||||
fs.utimesSync(oldPath, new Date(0), new Date(0));
|
||||
cleanup(todayPath);
|
||||
|
||||
logInfo("roll-me");
|
||||
|
||||
expect(fs.existsSync(todayPath)).toBe(true);
|
||||
expect(fs.readFileSync(todayPath, "utf-8")).toContain("roll-me");
|
||||
expect(fs.existsSync(oldPath)).toBe(false);
|
||||
|
||||
cleanup(todayPath);
|
||||
});
|
||||
});
|
||||
|
||||
function pathForTest() {
|
||||
|
||||
Reference in New Issue
Block a user