fix(logging ): use local timezone for console log timestamps (#25970)

Merged via squash.

Prepared head SHA: 30123265b7
Co-authored-by: openperf <80630709+openperf@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
This commit is contained in:
wangchunyue
2026-03-04 05:31:41 +08:00
committed by GitHub
parent e4b4486a96
commit bcd58c26d3
2 changed files with 9 additions and 4 deletions

View File

@@ -3,7 +3,11 @@ import type { Logger as TsLogger } from "tslog";
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";
@@ -197,7 +201,7 @@ function formatConsoleLine(opts: {
opts.style === "json" ? opts.subsystem : formatSubsystemForConsole(opts.subsystem);
if (opts.style === "json") {
return JSON.stringify({
time: new Date().toISOString(),
time: formatConsoleTimestamp("json"),
level: opts.level,
subsystem: displaySubsystem,
message: opts.message,
@@ -218,10 +222,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 "";
})();