mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
7e3d177d00
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.
27 lines
624 B
JavaScript
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
|