File size: 1,350 Bytes
fc93158 | 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 | import crypto from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { getLogger, resetLogger, setLoggerOverride } from "../logging.js";
describe("logger timestamp format", () => {
let logPath = "";
beforeEach(() => {
logPath = path.join(os.tmpdir(), `openclaw-log-ts-${crypto.randomUUID()}.log`);
resetLogger();
setLoggerOverride(null);
});
afterEach(() => {
resetLogger();
setLoggerOverride(null);
try {
fs.rmSync(logPath, { force: true });
} catch {
// ignore cleanup errors
}
});
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$/);
});
});
|