From c389839557b3976720d003c07ce3f7b3193c9e6f Mon Sep 17 00:00:00 2001 From: "TZU-YEN, CHANG" Date: Mon, 4 May 2020 02:53:00 +0800 Subject: [PATCH] feat(logger): add the silent mode and format dependent on NODE_ENV --- packages/logger/src/index.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/logger/src/index.ts b/packages/logger/src/index.ts index 4dfa318..b64568f 100644 --- a/packages/logger/src/index.ts +++ b/packages/logger/src/index.ts @@ -7,11 +7,12 @@ function isError(target: any): target is Error { } export enum LogLevel { - error = 0, - warn = 1, - info = 2, - debug = 3, - verbose = 4 + silent = 0, + error = 1, + warn = 2, + info = 3, + debug = 4, + verbose = 5 } export type LogColor = { @@ -101,6 +102,7 @@ export function print( * const error = printWith({ * level: LogLevel.error, * color: defaultColors.error + * format: process.env.NODE_ENV !== 'production' * }) * error('Hello World!') * @@ -111,25 +113,30 @@ export function printWith(options: LogOptions) { export const error = printWith({ level: LogLevel.error, - color: defaultColors.error + color: defaultColors.error, + format: process.env.NODE_ENV !== 'production' }) export const warn = printWith({ level: LogLevel.warn, - color: defaultColors.warn + color: defaultColors.warn, + format: process.env.NODE_ENV !== 'production' }) export const info = printWith({ level: LogLevel.info, - color: defaultColors.info + color: defaultColors.info, + format: process.env.NODE_ENV !== 'production' }) export const debug = printWith({ level: LogLevel.debug, - color: defaultColors.debug + color: defaultColors.debug, + format: process.env.NODE_ENV !== 'production' }) export const verbose = printWith({ level: LogLevel.verbose, - color: defaultColors.verbose + color: defaultColors.verbose, + format: process.env.NODE_ENV !== 'production' })