This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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