로그 파일에서 query 결과가 잘려보이는 오류 수정 (3), 로그 시간 오류 수정

This commit is contained in:
2026-07-04 17:58:58 +09:00
parent 7e2f629681
commit 8269eee996
3 changed files with 26 additions and 4 deletions
+16 -1
View File
@@ -18,6 +18,21 @@ function shouldLog(level: Level): boolean {
return PRIORITY[level] >= PRIORITY[getMinLevel()];
}
// TZ 환경변수 기준 로컬 시간 (toISOString은 항상 UTC라 사용하지 않음)
export function timestamp(): string {
const d = new Date();
const pad = (n: number, w = 2) => String(n).padStart(w, "0");
const offMin = -d.getTimezoneOffset();
const sign = offMin >= 0 ? "+" : "-";
const abs = Math.abs(offMin);
return (
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}` +
`T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}` +
`.${pad(d.getMilliseconds(), 3)}` +
`${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`
);
}
function write(
level: Level,
ctx: string,
@@ -25,7 +40,7 @@ function write(
data?: Record<string, unknown>
): void {
if (!shouldLog(level)) return;
const ts = new Date().toISOString();
const ts = timestamp();
const tag = level.toUpperCase().padEnd(5);
const line = data
? `[${ts}] [${tag}] [${ctx}] ${message} ${JSON.stringify(data)}`