This repository was archived by the owner on Jul 27, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 4141 },
4242 "dependencies" : {
4343 "chalk" : " ^1.1.3" ,
44- "error-stack-parser" : " ^2.0.0"
44+ "error-stack-parser" : " ^2.0.0" ,
45+ "string-length" : " ^1.0.1"
4546 }
4647}
Original file line number Diff line number Diff line change 22
33const colors = require ( './utils/colors' ) ;
44const chalk = require ( 'chalk' ) ;
5- const readline = require ( 'readline' )
5+ const stringLength = require ( 'string-length' ) ;
66
77class Debugger {
88
@@ -49,9 +49,26 @@ class Debugger {
4949
5050 title ( severity , title , subtitle ) {
5151 if ( this . enabled ) {
52+ const date = new Date ( ) ;
53+ const dateString = chalk . grey ( date . toLocaleTimeString ( ) ) ;
5254 const titleFormatted = colors . formatTitle ( severity , title ) ;
5355 const subTitleFormatted = colors . formatText ( severity , subtitle ) ;
54- this . log ( titleFormatted , subTitleFormatted ) ;
56+ const message = `${ titleFormatted } ${ subTitleFormatted } `
57+
58+ // In test environment we don't include timestamp
59+ if ( process . env . NODE_ENV === 'test' ) {
60+ this . log ( message ) ;
61+ this . log ( ) ;
62+ return ;
63+ }
64+
65+ // Make timestamp appear at the end of the line
66+ let logSpace = process . stdout . columns - stringLength ( message ) - stringLength ( dateString )
67+ if ( logSpace <= 0 ) {
68+ logSpace = 10
69+ }
70+
71+ this . log ( `${ message } ${ ' ' . repeat ( logSpace ) } ${ dateString } ` ) ;
5572 this . log ( ) ;
5673 }
5774 }
Original file line number Diff line number Diff line change @@ -3090,6 +3090,12 @@ string_decoder@^0.10.25, string_decoder@~0.10.x:
30903090 version "0.10.31"
30913091 resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
30923092
3093+ string-length@^1.0.1 :
3094+ version "1.0.1"
3095+ resolved "https://registry.yarnpkg.com/string-length/-/string-length-1.0.1.tgz#56970fb1c38558e9e70b728bf3de269ac45adfac"
3096+ dependencies :
3097+ strip-ansi "^3.0.0"
3098+
30933099string-width@^1.0.1, string-width@^1.0.2 :
30943100 version "1.0.2"
30953101 resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"
You can’t perform that action at this time.
0 commit comments