@@ -36,12 +36,14 @@ const CONFIG = {
3636const LEVELS = [ "success" , "debug" , "info" , "warn" , "error" , "disable" ] ;
3737
3838class Logger {
39- constructor ( ) {
39+ constructor ( name ) {
4040 // Current command
4141 this . command = '' ;
4242 // Last line
4343 this . lastCommand = '' ;
4444
45+ this . name = name || ""
46+
4547 // set level from env
4648 const level = process . env . LOGGER ;
4749 if ( this . isLevelValid ( level ) ) {
@@ -53,6 +55,10 @@ class Logger {
5355 this . _getDate = ( ) => ( new Date ( ) ) . toISOString ( ) ;
5456 }
5557
58+ createNamedLogger ( name ) {
59+ return new Logger ( name )
60+ }
61+
5662 setLevel ( level ) {
5763 if ( this . isLevelValid ( level ) ) {
5864 this . level = level ;
@@ -130,8 +136,12 @@ class Logger {
130136 this . _getDate = callback ;
131137 }
132138
133- getDate ( ) {
134- return this . _getDate ( ) ;
139+ getPrefix ( ) {
140+ if ( this . name ) {
141+ return `${ this . _getDate ( ) } [${ this . name } ]` ;
142+ } else {
143+ return this . _getDate ( ) ;
144+ }
135145 }
136146
137147 color ( ticket ) {
@@ -241,10 +251,10 @@ class Logger {
241251 return ;
242252
243253 if ( this . noColor ) {
244- const d = this . getDate ( ) ;
254+ const d = this . getPrefix ( ) ;
245255 this . log ( d , " [ERROR] " , ...args ) ;
246256 } else {
247- const d = this . getDate ( ) ;
257+ const d = this . getPrefix ( ) ;
248258 this . log ( d + " " ) . joint ( )
249259 . bgColor ( 'red' ) . log ( '[ERROR]' ) . joint ( )
250260 . log ( " " ) . joint ( )
@@ -257,10 +267,10 @@ class Logger {
257267 return ;
258268
259269 if ( this . noColor ) {
260- const d = this . getDate ( ) ;
270+ const d = this . getPrefix ( ) ;
261271 this . log ( d , " [WARN] " , ...args ) ;
262272 } else {
263- const d = this . getDate ( ) ;
273+ const d = this . getPrefix ( ) ;
264274 this . log ( d + " " ) . joint ( )
265275 . bgColor ( 'yellow' ) . color ( 'black' ) . log ( '[WARN]' ) . joint ( )
266276 . log ( " " ) . joint ( )
@@ -273,10 +283,10 @@ class Logger {
273283 return ;
274284
275285 if ( this . noColor ) {
276- const d = this . getDate ( ) ;
286+ const d = this . getPrefix ( ) ;
277287 this . log ( d , " [INFO] " , ...args ) ;
278288 } else {
279- const d = this . getDate ( ) ;
289+ const d = this . getPrefix ( ) ;
280290 this . log ( d + " " ) . joint ( )
281291 . bgColor ( 'green' ) . color ( 'black' ) . log ( '[INFO]' ) . joint ( )
282292 . log ( " " ) . joint ( )
@@ -289,10 +299,10 @@ class Logger {
289299 return ;
290300
291301 if ( this . noColor ) {
292- const d = this . getDate ( ) ;
302+ const d = this . getPrefix ( ) ;
293303 this . log ( d , " [DEBUG] " , ...args ) ;
294304 } else {
295- const d = this . getDate ( ) ;
305+ const d = this . getPrefix ( ) ;
296306 this . log ( d + " " ) . joint ( )
297307 . bgColor ( 'cyan' ) . color ( 'black' ) . log ( "[DEBUG]" ) . joint ( )
298308 . log ( ' ' ) . joint ( )
@@ -306,10 +316,10 @@ class Logger {
306316 return ;
307317
308318 if ( this . noColor ) {
309- const d = this . getDate ( ) ;
319+ const d = this . getPrefix ( ) ;
310320 this . log ( d , " [SUCCESS] " , ...args ) ;
311321 } else {
312- const d = this . getDate ( ) ;
322+ const d = this . getPrefix ( ) ;
313323 this . log ( d + " " ) . joint ( )
314324 . bgColor ( 'green' ) . color ( 'black' ) . log ( "[SUCCESS]" ) . joint ( )
315325 . log ( ' ' ) . joint ( )
0 commit comments