2019-08-26 17:02:06 +00:00
|
|
|
const { inspect } = require('util')
|
|
|
|
|
2019-09-08 01:56:29 +00:00
|
|
|
const self = {}
|
2019-08-26 17:02:06 +00:00
|
|
|
|
2019-09-08 01:56:29 +00:00
|
|
|
const clean = item => {
|
2019-08-26 17:02:06 +00:00
|
|
|
if (typeof item === 'string') return item
|
|
|
|
const cleaned = inspect(item, { depth: 0 })
|
|
|
|
return cleaned
|
|
|
|
}
|
|
|
|
|
2019-09-08 01:56:29 +00:00
|
|
|
const write = (content, options = {}) => {
|
2019-08-26 17:02:06 +00:00
|
|
|
const date = new Date().toISOString()
|
|
|
|
.replace(/T/, ' ')
|
|
|
|
.replace(/\..*/, '')
|
|
|
|
const stream = options.error ? process.stderr : process.stdout
|
2019-09-08 01:56:29 +00:00
|
|
|
stream.write(`[${date}]: ${options.prefix || ''}${clean(content)}\n`)
|
2019-08-26 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-08 01:56:29 +00:00
|
|
|
self.log = write
|
2019-08-26 17:02:06 +00:00
|
|
|
|
2019-09-08 01:56:29 +00:00
|
|
|
self.error = (content, options = {}) => {
|
2019-08-26 17:02:06 +00:00
|
|
|
options.error = true
|
2019-09-08 01:56:29 +00:00
|
|
|
write(content, options)
|
2019-08-26 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-08 01:56:29 +00:00
|
|
|
module.exports = self
|