40be5a5f8e
* Extend line width to 120 * Lint fixes
30 lines
545 B
JavaScript
30 lines
545 B
JavaScript
module.exports = function logger(name) {
|
|
let lastlog = 0
|
|
|
|
function log(...args) {
|
|
const now = new Date()
|
|
console.log(now.toISOString(), `(+${lastlog ? now.getTime() - lastlog : 0}ms)`, `[${name}]`, ...args)
|
|
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
|
|
}
|
|
}
|