Merge 533fb94be6 into bc432d8435
This commit is contained in:
commit
5f46420e3e
@ -8,6 +8,7 @@ import { type LogLevel, normalizeLogLevel } from "./levels.js";
|
|||||||
import { getLogger, type LoggerSettings } from "./logger.js";
|
import { getLogger, type LoggerSettings } from "./logger.js";
|
||||||
import { readLoggingConfig } from "./config.js";
|
import { readLoggingConfig } from "./config.js";
|
||||||
import { loggingState } from "./state.js";
|
import { loggingState } from "./state.js";
|
||||||
|
import { formatLocalHHMMSS } from "./time.js";
|
||||||
|
|
||||||
export type ConsoleStyle = "pretty" | "compact" | "json";
|
export type ConsoleStyle = "pretty" | "compact" | "json";
|
||||||
type ConsoleSettings = {
|
type ConsoleSettings = {
|
||||||
@ -129,9 +130,8 @@ function isEpipeError(err: unknown): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatConsoleTimestamp(style: ConsoleStyle): string {
|
function formatConsoleTimestamp(style: ConsoleStyle): string {
|
||||||
const now = new Date().toISOString();
|
if (style === "pretty") return formatLocalHHMMSS();
|
||||||
if (style === "pretty") return now.slice(11, 19);
|
return new Date().toISOString();
|
||||||
return now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasTimestampPrefix(value: string): boolean {
|
function hasTimestampPrefix(value: string): boolean {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import { isVerbose } from "../globals.js";
|
|||||||
import { type LogLevel, levelToMinLevel } from "./levels.js";
|
import { type LogLevel, levelToMinLevel } from "./levels.js";
|
||||||
import { getChildLogger } from "./logger.js";
|
import { getChildLogger } from "./logger.js";
|
||||||
import { loggingState } from "./state.js";
|
import { loggingState } from "./state.js";
|
||||||
|
import { formatLocalHHMMSS } from "./time.js";
|
||||||
import { clearActiveProgressLine } from "../terminal/progress-line.js";
|
import { clearActiveProgressLine } from "../terminal/progress-line.js";
|
||||||
|
|
||||||
type LogObj = { date?: Date } & Record<string, unknown>;
|
type LogObj = { date?: Date } & Record<string, unknown>;
|
||||||
@ -152,7 +153,7 @@ function formatConsoleLine(opts: {
|
|||||||
const displayMessage = stripRedundantSubsystemPrefixForConsole(opts.message, displaySubsystem);
|
const displayMessage = stripRedundantSubsystemPrefixForConsole(opts.message, displaySubsystem);
|
||||||
const time = (() => {
|
const time = (() => {
|
||||||
if (opts.style === "pretty") {
|
if (opts.style === "pretty") {
|
||||||
return color.gray(new Date().toISOString().slice(11, 19));
|
return color.gray(formatLocalHHMMSS());
|
||||||
}
|
}
|
||||||
if (loggingState.consoleTimestampPrefix) {
|
if (loggingState.consoleTimestampPrefix) {
|
||||||
return color.gray(new Date().toISOString());
|
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