From c9177eb379a76e96202d651339b87a4ede7ef62d Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 20 Sep 2024 08:27:53 +0800 Subject: [PATCH] chore: use locale time in pretty log --- src/types.ts | 1 + src/utils.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index c6ed32c..615b97b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,6 +21,7 @@ export enum Format { export interface Log { '@timestamp': string + '@localetime': string 'level': LogLevelString 'fields': { context?: string diff --git a/src/utils.ts b/src/utils.ts index 783c710..08035f7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -47,6 +47,7 @@ export function newLog(logLevel: LogLevelString, context: string, fields: Record const raw: Log = { '@timestamp': new Date().toISOString(), + '@localetime': new Date().toLocaleString(), 'level': logLevel, 'fields': fieldsObj, 'message': messageString, @@ -69,7 +70,7 @@ export function newErrorLog(logLevel: LogLevelString, context: string, fields: R export function toPrettyString(log: Log): string { const messagePartials: string[] = [] - messagePartials.push(log['@timestamp']) + messagePartials.push(log['@localetime']) messagePartials.push( logLevelToChalkColorMap[logLevelStringToLogLevelMap[log.level]]( `[${log.level}]`,