Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const dgram = require('dgram')
const glossy = require('glossy')
const syslogProducer = new glossy.Produce()
const socket = dgram.createSocket('udp4')
const sendToPapertrail = (chunk, { severity }) => {
const syslog = syslogProducer.produce({
facility: 'user',
severity,
host : config.host,
appName : config.appName,
pid : process.pid,
time : new Date(),
message : String(chunk),
})
socket.send(syslog, 0, syslog.length, config.port, config.host, err => {
if (err) {
console.error(err)
}
})
}
for (const streamName of ['stdout', 'stderr']) {
const streamWrite = process[streamName].write.bind(process[streamName])
process[streamName].write = (chunk, encoding, cb) => {
sendToPapertrail(chunk, {
severity: streamName === 'stdout'
? 6 // Info
: 4 // Warning
})
return streamWrite(chunk, encoding, cb)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment