로그 파일에서 query 결과가 잘려보이는 오류 수정 (3), 로그 시간 오류 수정
This commit is contained in:
+16
-1
@@ -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)}`
|
||||
|
||||
Reference in New Issue
Block a user