File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,13 @@ export default class Logger extends DenaliObject {
3030 */
3131 colorize = true ;
3232
33+ /**
34+ * Specify if logs should be colorized.
35+ *
36+ * @since 0.1.3
37+ */
38+ timestamps = true ;
39+
3340 /**
3441 * Available log levels that can be used.
3542 */
@@ -82,16 +89,21 @@ export default class Logger extends DenaliObject {
8289 if ( this . levels . indexOf ( level ) === - 1 ) {
8390 level = this . loglevel ;
8491 }
85- let timestamp = ( new Date ( ) ) . toISOString ( ) ;
8692 let padLength = this . levels . reduce ( ( n : number , label ) => Math . max ( n , label . length ) , null ) ;
8793 let levelLabel = padStart ( level . toUpperCase ( ) , padLength ) ;
8894 if ( this . colorize ) {
8995 let colorizer = this . colors [ level ] || identity ;
9096 msg = colorizer ( msg ) ;
9197 levelLabel = colorizer ( levelLabel ) ;
9298 }
99+ let parts : string [ ] = [ ] ;
100+ if ( this . timestamps ) {
101+ parts . push ( `[${ ( new Date ( ) ) . toISOString ( ) } ]` ) ;
102+ }
103+ parts . push ( levelLabel ) ;
104+ parts . push ( msg ) ;
93105 /* tslint:disable:no-console no-debugger */
94- console . log ( `[ ${ timestamp } ] ${ levelLabel } - ${ msg } ` ) ;
106+ console . log ( parts . join ( ' ' ) ) ;
95107 if ( level === 'error' ) {
96108 debugger ;
97109 }
You can’t perform that action at this time.
0 commit comments