fix(logging): use local timezone for console timestamps
Console log timestamps now respect the TZ environment variable instead of always using UTC. This only affects pretty-style console output; compact, JSON, and file logs remain in UTC for tool compatibility. Closes #3867
This commit is contained in:
parent
6372242da7
commit
533fb94be6
@ -8,6 +8,7 @@ import { type LogLevel, normalizeLogLevel } from "./levels.js";
|
||||
import { getLogger, type LoggerSettings } from "./logger.js";
|
||||
import { readLoggingConfig } from "./config.js";
|
||||
import { loggingState } from "./state.js";
|
||||
import { formatLocalHHMMSS } from "./time.js";
|
||||
|
||||
export type ConsoleStyle = "pretty" | "compact" | "json";
|
||||
type ConsoleSettings = {
|
||||
@ -129,9 +130,8 @@ function isEpipeError(err: unknown): boolean {
|
||||
}
|
||||
|
||||
function formatConsoleTimestamp(style: ConsoleStyle): string {
|
||||
const now = new Date().toISOString();
|
||||
if (style === "pretty") return now.slice(11, 19);
|
||||
return now;
|
||||
if (style === "pretty") return formatLocalHHMMSS();
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
function hasTimestampPrefix(value: string): boolean {
|
||||
|
||||
@ -8,6 +8,7 @@ import { isVerbose } from "../globals.js";
|
||||
import { type LogLevel, levelToMinLevel } from "./levels.js";
|
||||
import { getChildLogger } from "./logger.js";
|
||||
import { loggingState } from "./state.js";
|
||||
import { formatLocalHHMMSS } from "./time.js";
|
||||
import { clearActiveProgressLine } from "../terminal/progress-line.js";
|
||||
|
||||
type LogObj = { date?: Date } & Record<string, unknown>;
|
||||
@ -152,7 +153,7 @@ 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(formatLocalHHMMSS());
|
||||
}
|
||||
if (loggingState.consoleTimestampPrefix) {
|
||||
return color.gray(new Date().toISOString());
|
||||
|
||||
11
src/logging/time.ts
Normal file
11
src/logging/time.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Formats the current local time as HH:MM:SS.
|
||||
* Respects the system TZ environment variable.
|
||||
*/
|
||||
export function formatLocalHHMMSS(): string {
|
||||
const now = new Date();
|
||||
const hours = String(now.getHours()).padStart(2, "0");
|
||||
const minutes = String(now.getMinutes()).padStart(2, "0");
|
||||
const seconds = String(now.getSeconds()).padStart(2, "0");
|
||||
return `${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user