@@ -4,21 +4,23 @@ module.exports = class Logger {
44 }
55
66 log ( message , type ) {
7- let type2 = null
8- let iserr = false
7+ let t = null
8+ let e = false
9+ const a = "\x1b["
910
10- if ( type === "DEBUG" ) type2 = "\x1b[95mDEBUG\x1b[0m "
11- if ( type === "SUCCESS" ) type2 = "\x1b[92mSUCCESS\x1b[0m"
12- if ( type === "INFO" ) type2 = "\x1b[94mINFO\x1b[0m "
13- if ( type === "WARN" ) type2 = "\x1b[93mWARN\x1b[0m "
14- if ( type === "ERROR" ) { type2 = "\x1b[41mERROR\x1b[0m " ; iserr = true }
15- if ( type === "FATAL" ) { type2 = "\x1b[101mFATAL\x1b[0m " ; iserr = true }
11+ if ( type === "DEBUG" ) t = `${ a } 95mDEBUG${ a } 0m `
12+ if ( type === "DEBUG" && this . production ) return
13+ if ( type === "SUCCESS" ) t = `${ a } 92mSUCCESS${ a } 0m`
14+ if ( type === "INFO" ) t = `${ a } 94mINFO${ a } 0m `
15+ if ( type === "WARN" ) t = `${ a } 93mWARN${ a } 0m `
16+ if ( type === "ERROR" ) { t = `${ a } 41mERROR${ a } 0m ` ; e = true }
17+ if ( type === "FATAL" ) { t = `${ a } 101mFATAL${ a } 0m ` ; e = true }
1618
17- const ret = ( new Error ( ) ) . stack . split ( '\n' ) [ 3 ] . split ( '(' ) [ 1 ] . split ( ')' ) [ 0 ] ;
18- const date = new Date ( ) ;
19- const printstr = `\x1b[ 2m[${ date . getFullYear ( ) } -${ date . getMonth ( ) } -${ date . getDay ( ) } ${ date . getHours ( ) } :${ date . getMinutes ( ) } :${ date . getSeconds ( ) } .${ date . getMilliseconds ( ) } ]\x1b[ 0m ${ type2 } \x1b[ 2m[${ ret . substr ( 0 , ret . lastIndexOf ( ":" ) ) } ]\x1b[ 0m ${ message } \n`
19+ const r = ( new Error ( ) ) . stack . split ( '\n' ) [ 3 ] . split ( '(' ) [ 1 ] . split ( ')' ) [ 0 ] ;
20+ const d = new Date ( ) ;
21+ const p = `${ a } 2m[${ d . getFullYear ( ) } -${ d . getMonth ( ) } -${ d . getDay ( ) } ${ d . getHours ( ) } :${ d . getMinutes ( ) } :${ d . getSeconds ( ) } .${ d . getMilliseconds ( ) } ]${ a } 0m ${ t } ${ a } 2m[${ r . substr ( 0 , r . lastIndexOf ( ":" ) ) } ]${ a } 0m ${ message } \n`
2022
21- if ( iserr ) process . stderr . write ( printstr )
22- else process . stdout . write ( printstr )
23+ if ( e ) process . stderr . write ( p )
24+ else process . stdout . write ( p )
2325 }
2426 }
0 commit comments