diff --git a/src/logging/subsystem.test.ts b/src/logging/subsystem.test.ts index e389d78ba8ac5..fd1240080cbcd 100644 --- a/src/logging/subsystem.test.ts +++ b/src/logging/subsystem.test.ts @@ -1,4 +1,5 @@ -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import * as consoleModule from "./console.js"; import { setConsoleSubsystemFilter } from "./console.js"; import { resetLogger, setLoggerOverride } from "./logger.js"; import { createSubsystemLogger } from "./subsystem.js"; @@ -53,4 +54,16 @@ describe("createSubsystemLogger().isEnabled", () => { expect(log.isEnabled("info", "file")).toBe(true); expect(log.isEnabled("info")).toBe(true); }); + + it("uses local console timestamp formatter for pretty output", () => { + setLoggerOverride({ level: "silent", consoleLevel: "info", consoleStyle: "pretty" }); + const timestampSpy = vi.spyOn(consoleModule, "formatConsoleTimestamp"); + const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {}); + const log = createSubsystemLogger("agent/embedded"); + + log.info("hello"); + + expect(timestampSpy).toHaveBeenCalledWith("pretty"); + expect(consoleSpy).toHaveBeenCalledTimes(1); + }); }); diff --git a/src/logging/subsystem.ts b/src/logging/subsystem.ts index 32fe853f081cf..44c9794bdb0f5 100644 --- a/src/logging/subsystem.ts +++ b/src/logging/subsystem.ts @@ -4,7 +4,11 @@ import { CHAT_CHANNEL_ORDER } from "../channels/registry.js"; import { isVerbose } from "../globals.js"; import { defaultRuntime, type RuntimeEnv } from "../runtime.js"; import { clearActiveProgressLine } from "../terminal/progress-line.js"; -import { getConsoleSettings, shouldLogSubsystemToConsole } from "./console.js"; +import { + formatConsoleTimestamp, + getConsoleSettings, + shouldLogSubsystemToConsole, +} from "./console.js"; import { type LogLevel, levelToMinLevel } from "./levels.js"; import { getChildLogger, isFileLogLevelEnabled } from "./logger.js"; import { loggingState } from "./state.js"; @@ -209,10 +213,10 @@ function formatConsoleLine(opts: { const displayMessage = stripRedundantSubsystemPrefixForConsole(opts.message, displaySubsystem); const time = (() => { if (opts.style === "pretty") { - return color.gray(new Date().toISOString().slice(11, 19)); + return color.gray(formatConsoleTimestamp("pretty")); } if (loggingState.consoleTimestampPrefix) { - return color.gray(new Date().toISOString()); + return color.gray(formatConsoleTimestamp(opts.style)); } return ""; })();