Skip to content

Instantly share code, notes, and snippets.

@delvedor
Last active May 29, 2017 16:28
Show Gist options
  • Save delvedor/10331afd1a3b4673f865d1b2ccc9c114 to your computer and use it in GitHub Desktop.
Save delvedor/10331afd1a3b4673f865d1b2ccc9c114 to your computer and use it in GitHub Desktop.
const Pino = require('pino')
const spawn = require('child_process').spawn
const { MONGO_ADDRESS } = process.env
function eventLogger () {
const mongoLog = spawnMongoLog()
mongoLog.on('error', err => { throw err })
mongoLog.stdout.pipe(process.stdout)
const pino = Pino({
name: 'letzdoit-events',
level: 'info'
}, mongoLog.stdin)
return pino
}
function spawnMongoLog () {
return spawn(
'./node_modules/.bin/pino-mongodb',
[
'--host', MONGO_ADDRESS,
'--collection', 'logs'
]
)
}
module.exports = eventLogger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment