

















@@ -4,7 +4,6 @@ import { afterEach, describe, expect, it, vi } from "vitest";
44import { isVerbose, isYes, logVerbose, setVerbose, setYes } from "./globals.js";
55import { logDebug, logError, logInfo, logSuccess, logWarn } from "./logger.js";
66import {
7-DEFAULT_LOG_DIR,
87resetLogger,
98setLoggerOverride,
109stripRedundantSubsystemPrefixForConsole,
@@ -35,7 +34,7 @@ describe("logger helpers", () => {
3534});
36353736it("only logs debug when verbose is enabled", () => {
38-const logVerbose = vi.spyOn(console, "log");
37+const logVerbose = vi.spyOn(console, "log").mockImplementation(() => {});
3938setVerbose(false);
4039logDebug("quiet");
4140expect(logVerbose).not.toHaveBeenCalled();
@@ -70,26 +69,24 @@ describe("logger helpers", () => {
7069});
7170});
727173-it("uses daily rolling default log file and prunes old ones", () => {
74-resetLogger();
75-setLoggerOverride({ level: "info" }); // force default file path with enabled file logging
76-const today = localDateString(new Date());
77-const todayPath = path.join(DEFAULT_LOG_DIR, `openclaw-${today}.log`);
78-79-// create an old file to be pruned
80-const oldPath = path.join(DEFAULT_LOG_DIR, "openclaw-2000-01-01.log");
81-fs.mkdirSync(DEFAULT_LOG_DIR, { recursive: true });
82-fs.writeFileSync(oldPath, "old");
83-fs.utimesSync(oldPath, new Date(0), new Date(0));
84-fs.rmSync(todayPath, { force: true });
72+it("uses daily rolling log files and prunes old ones", () => {
73+withTempDirSync({ prefix: "openclaw-log-test-" }, (dir) => {
74+resetLogger();
75+const today = localDateString(new Date());
76+const todayPath = path.join(dir, `openclaw-${today}.log`);
77+setLoggerOverride({ level: "info", file: todayPath });
857886-logInfo("roll-me");
79+// create an old file to be pruned
80+const oldPath = path.join(dir, "openclaw-2000-01-01.log");
81+fs.writeFileSync(oldPath, "old");
82+fs.utimesSync(oldPath, new Date(0), new Date(0));
878388-expect(fs.existsSync(todayPath)).toBe(true);
89-expect(fs.readFileSync(todayPath, "utf-8")).toContain("roll-me");
90-expect(fs.existsSync(oldPath)).toBe(false);
84+logInfo("roll-me");
918592-fs.rmSync(todayPath, { force: true });
86+expect(fs.existsSync(todayPath)).toBe(true);
87+expect(fs.readFileSync(todayPath, "utf-8")).toContain("roll-me");
88+expect(fs.existsSync(oldPath)).toBe(false);
89+});
9390});
9491});
9592此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。