-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0375232
commit df2f794
Showing
4 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export enum LOG_LEVEL { | ||
INFO = 'INFO', | ||
WARN = 'WARN', | ||
ERROR = 'ERROR', | ||
} | ||
|
||
const loggerFn = { | ||
[LOG_LEVEL.ERROR]: console.error, | ||
[LOG_LEVEL.INFO]: console.log, | ||
[LOG_LEVEL.WARN]: console.warn, | ||
} | ||
|
||
export function log(level: LOG_LEVEL) { | ||
return (message: string, meta: Record<string, string> = {}) => { | ||
const metaString = Object.entries(meta) | ||
.filter(([, value]) => Boolean(value)) | ||
.map(([key, value]) => `[${key}=${value}]`) | ||
.join('') | ||
|
||
loggerFn[level](`[${level}]${metaString} ${message}`) | ||
} | ||
} | ||
|
||
export const info = log(LOG_LEVEL.INFO) | ||
export const warn = log(LOG_LEVEL.WARN) | ||
export const error = log(LOG_LEVEL.ERROR) |