@@ -19,14 +19,20 @@ export type Log = LogFn & {
19
19
20
20
type LogLevel = keyof typeof colors
21
21
22
+ const formatDate = ( date : Date ) => {
23
+ return [ date . getHours ( ) , date . getMinutes ( ) , date . getSeconds ( ) ]
24
+ . map ( ( n ) => n . toString ( ) . padStart ( 2 , '0' ) )
25
+ . join ( ':' )
26
+ }
27
+
22
28
/**
23
29
* Logs a message to the console. The level is displayed in ANSI colors,
24
30
* either bright red in case of an error or green otherwise.
25
31
*/
26
32
export const makeLog = function ( cfg : Config ) {
27
33
function log ( msg : string , level : LogLevel ) {
28
34
if ( cfg . quiet && level === 'info' ) return
29
- if ( cfg . timestamp ) msg = color ( new Date ( cfg . timestamp ) . toLocaleString ( ) , '30;1' ) + ' ' + msg
35
+ if ( cfg . timestamp ) msg = color ( formatDate ( new Date ( ) ) , '30;1' ) + ' ' + msg
30
36
const c = colors [ level . toLowerCase ( ) as LogLevel ] || '32'
31
37
console . log ( '[' + color ( level . toUpperCase ( ) , c ) + '] ' + msg )
32
38
}
@@ -42,7 +48,7 @@ export const makeLog = function (cfg: Config) {
42
48
if ( ! cfg . debug ) return
43
49
log ( util . format . apply ( util , arguments ) , 'debug' )
44
50
}
45
- log . info = function ( ) {
51
+ log . info = function ( ) {
46
52
log ( util . format . apply ( util , arguments ) , 'info' )
47
53
}
48
54
0 commit comments