2019-05-08 16:12:02 +03:00
|
|
|
module.exports = function logger(name) {
|
|
|
|
let lastlog = 0
|
|
|
|
|
|
|
|
function log(...args) {
|
|
|
|
const now = new Date()
|
2019-08-01 16:10:22 +03:00
|
|
|
console.log(now.toISOString(), `(+${lastlog ? now.getTime() - lastlog : 0}ms)`, `[${name}]`, ...args)
|
2019-05-08 16:12:02 +03:00
|
|
|
lastlog = now.getTime()
|
|
|
|
}
|
|
|
|
|
|
|
|
function error(...args) {
|
|
|
|
const now = new Date()
|
|
|
|
console.error(now.toISOString(), `[${name}]`, ...args)
|
|
|
|
}
|
|
|
|
|
|
|
|
let dbg
|
|
|
|
if (process.env.DEBUG) {
|
|
|
|
dbg = (...args) => {
|
|
|
|
log(...args)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dbg = () => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
log,
|
|
|
|
error,
|
|
|
|
debug: dbg
|
|
|
|
}
|
|
|
|
}
|