tokenbridge/monitor/logger.js
Przemyslaw Rzad 5efc9a6688
Update bridge monitor (#38)
* Removed duplicate licence, updated links do Contributing and Licence in sub-readme.

* Renamed bridge-monitor to monitor.

* Removed package-lock.json.

* Added monitor workspace with linting.

* Consistent eslint version.

* Added readme for merging.
2019-05-14 09:17:03 +02:00

35 lines
575 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
}
}