Skip to content

Commit 8797c3a

Browse files
committed
feat: debug.log add datetime info
1 parent c13e3d8 commit 8797c3a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/debug.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const os = require('os');
44
const { prompt } = require('enquirer');
5+
const moment = require('moment');
56

67
var count = 0;
78

@@ -10,11 +11,11 @@ function emit(data) {
1011
data.forEach(d => console.log(d));
1112
}
1213

13-
function pos(label, color = '33') {
14+
function pos(label, color = '33', prefix = '', suffix = '') {
1415
const stack = (new Error()).stack;
1516
let tmp = stack.split('\n');
1617
let local = tmp[3].indexOf('at Object.jump') > -1 ? tmp[4] : tmp[3];
17-
process.stdout.write(`\x1b[${color}m${label} ${local.trim()}\x1b[0m${os.EOL}`);
18+
process.stdout.write(`${prefix}\x1b[${color}m${label} ${local.trim()}\x1b[0m${suffix}${os.EOL}`);
1819
}
1920

2021
function dump(...data) {
@@ -26,7 +27,7 @@ function dump(...data) {
2627
}
2728

2829
function log(...data) {
29-
pos('log', '38;5;243');
30+
pos('log', '38;5;243', `\x1b[33m[${moment().format('YYYY-MM-DD HH:mm:ss')}]\x1b[0m `);
3031
// eslint-disable-next-line no-console
3132
console.log.apply(this, data);
3233
}

0 commit comments

Comments
 (0)