46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
|
// Readline
|
||
|
const readline = require('readline')
|
||
|
const rl = readline.createInterface({
|
||
|
input: process.stdin,
|
||
|
output: process.stdout
|
||
|
})
|
||
|
|
||
|
// Logging
|
||
|
function pz (z) {
|
||
|
if (z < 10) {
|
||
|
return '0' + z
|
||
|
}
|
||
|
return z
|
||
|
}
|
||
|
|
||
|
function dateFormat (date) {
|
||
|
return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' ' +
|
||
|
pz(date.getHours()) + ':' + pz(date.getMinutes()) + ':' + pz(date.getSeconds())
|
||
|
}
|
||
|
|
||
|
const realConsoleLog = console.log
|
||
|
console.log = function () {
|
||
|
rl.output.write('\x1b[2K\r')
|
||
|
rl.output.write('[info] [' + dateFormat(new Date()) + '] ')
|
||
|
realConsoleLog.apply(this, arguments)
|
||
|
rl && rl.prompt(true)
|
||
|
}
|
||
|
|
||
|
const realConsoleWarn = console.warn
|
||
|
console.warn = function () {
|
||
|
rl.output.write('\x1b[2K\r')
|
||
|
rl.output.write('[warn] [' + dateFormat(new Date()) + '] ')
|
||
|
realConsoleWarn.apply(this, arguments)
|
||
|
rl && rl.prompt(true)
|
||
|
}
|
||
|
|
||
|
const realConsoleError = console.error
|
||
|
console.error = function () {
|
||
|
rl.output.write('\x1b[2K\r')
|
||
|
rl.output.write('[ err] [' + dateFormat(new Date()) + '] ')
|
||
|
realConsoleError.apply(this, arguments)
|
||
|
rl && rl.prompt(true)
|
||
|
}
|
||
|
|
||
|
module.exports = { realConsoleLog, realConsoleWarn, realConsoleError, rl }
|