Skip to content

Commit

Permalink
chore: use locale time in pretty log
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty authored and luoling8192 committed Sep 20, 2024
1 parent 347df03 commit c9177eb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum Format {

export interface Log {
'@timestamp': string
'@localetime': string
'level': LogLevelString
'fields': {
context?: string
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}]`,
Expand Down

0 comments on commit c9177eb

Please sign in to comment.