Mailspring/packages/nylas-core/log-streams.js
Juan Tejada 7f72ab7f14 Add loggly logging service to test it out
- Adds env to all logs, cleans up code a bit
2016-07-13 11:58:46 -07:00

58 lines
1.3 KiB
JavaScript

const os = require('os');
const createCWStream = require('bunyan-cloudwatch')
const PrettyStream = require('bunyan-prettystream')
const Bunyan2Loggly = require('bunyan-loggly')
const {LOGGLY_TOKEN} = process.env
const logglyConfig = (name, env) => ({
token: LOGGLY_TOKEN,
subdomain: 'nylas',
tags: [`${name}-${env}`],
})
const cloudwatchConfig = (name, env) => ({
logGroupName: `k2-${env}`,
logStreamName: `${name}-${env}-${os.hostname()}`,
cloudWatchLogsOptions: {
region: 'us-east-1',
},
})
const stdoutStream = {
level: 'info',
stream: process.stdout,
}
const getLogStreams = (name, env) => {
switch (env) {
case 'development': {
const prettyStdOut = new PrettyStream();
prettyStdOut.pipe(process.stdout);
return [
{
type: 'raw',
level: 'debug',
stream: prettyStdOut,
reemitErrorEvents: true,
},
]
}
default: {
return [
stdoutStream,
{
type: 'raw',
reemitErrorEvents: true,
stream: new Bunyan2Loggly(logglyConfig(name, env)),
},
{
type: 'raw',
reemitErrorEvents: true,
stream: createCWStream(cloudwatchConfig(name, env)),
},
]
}
}
}
module.exports = {getLogStreams}