filesafe/logger.js
Bobby Wibowo 7e3d177d00
Updated
Added logger.js to format console logs (adding timestamps).

Re-ordered modules loading in lolisafe.js, and a few other minor edits.

Updated dev dependencies.

A few other minor edits.
2019-08-27 00:02:06 +07:00

27 lines
624 B
JavaScript

const { inspect } = require('util')
const logger = {}
logger.clean = item => {
if (typeof item === 'string') return item
const cleaned = inspect(item, { depth: 0 })
return cleaned
}
logger.write = (content, options = {}) => {
const date = new Date().toISOString()
.replace(/T/, ' ')
.replace(/\..*/, '')
const stream = options.error ? process.stderr : process.stdout
stream.write(`[${date}]: ${options.prefix || ''}${logger.clean(content)}\n`)
}
logger.log = logger.write
logger.error = (content, options = {}) => {
options.error = true
logger.write(content, options)
}
module.exports = logger