forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger-timestamp.test.ts
More file actions
52 lines (42 loc) · 1.48 KB
/
Copy pathlogger-timestamp.test.ts
File metadata and controls
52 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import fs from "node:fs";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { getLogger, resetLogger, setLoggerOverride } from "../logging.js";
import { createSuiteLogPathTracker } from "./log-test-helpers.js";
const logPathTracker = createSuiteLogPathTracker("openclaw-log-ts-");
describe("logger timestamp format", () => {
let logPath = "";
beforeAll(async () => {
await logPathTracker.setup();
});
beforeEach(() => {
logPath = logPathTracker.nextPath();
resetLogger();
setLoggerOverride(null);
});
afterEach(() => {
resetLogger();
setLoggerOverride(null);
try {
fs.rmSync(logPath, { force: true });
} catch {
// ignore cleanup errors
}
});
afterAll(async () => {
await logPathTracker.cleanup();
});
it("uses local time format in file logs (not UTC)", () => {
setLoggerOverride({ level: "info", file: logPath });
const logger = getLogger();
// Write a log entry
logger.info("test-timestamp-format");
// Read the log file
const content = fs.readFileSync(logPath, "utf8");
const lines = content.trim().split("\n");
const lastLine = JSON.parse(lines[lines.length - 1]);
// Should use local time format like "2026-02-27T15:04:00.000+08:00"
// NOT UTC format like "2026-02-27T07:04:00.000Z"
expect(lastLine.time).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}[+-]\d{2}:\d{2}$/);
expect(lastLine.time).not.toMatch(/Z$/);
});
});