mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-01 04:50:59 +08:00
Add loggly logging service to test it out
- Adds env to all logs, cleans up code a bit
This commit is contained in:
parent
1c0c4ee61e
commit
7f72ab7f14
3 changed files with 60 additions and 34 deletions
|
@ -7,6 +7,7 @@
|
|||
"bluebird": "3.x.x",
|
||||
"bunyan": "1.8.0",
|
||||
"bunyan-cloudwatch": "2.0.0",
|
||||
"bunyan-loggly": "^1.0.0",
|
||||
"bunyan-prettystream": "^0.1.3",
|
||||
"lerna": "2.0.0-beta.23",
|
||||
"mysql": "^2.11.1",
|
||||
|
|
57
packages/nylas-core/log-streams.js
Normal file
57
packages/nylas-core/log-streams.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
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}
|
|
@ -1,44 +1,12 @@
|
|||
const os = require('os');
|
||||
const bunyan = require('bunyan')
|
||||
const createCWStream = require('bunyan-cloudwatch')
|
||||
const PrettyStream = require('bunyan-prettystream');
|
||||
const {getLogStreams} = require('./log-streams')
|
||||
const NODE_ENV = process.env.NODE_ENV || 'unknown'
|
||||
|
||||
|
||||
function getLogStreams(name, env) {
|
||||
if (env === 'development') {
|
||||
const prettyStdOut = new PrettyStream();
|
||||
prettyStdOut.pipe(process.stdout);
|
||||
const stdoutStream = {
|
||||
type: 'raw',
|
||||
level: 'debug',
|
||||
stream: prettyStdOut,
|
||||
}
|
||||
return [stdoutStream]
|
||||
}
|
||||
|
||||
const stdoutStream = {
|
||||
stream: process.stdout,
|
||||
level: 'info',
|
||||
}
|
||||
const cloudwatchStream = {
|
||||
stream: createCWStream({
|
||||
logGroupName: `k2-${env}`,
|
||||
logStreamName: `${name}-${env}-${os.hostname()}`,
|
||||
cloudWatchLogsOptions: {
|
||||
region: 'us-east-1',
|
||||
},
|
||||
}),
|
||||
type: 'raw',
|
||||
reemitErrorEvents: true,
|
||||
}
|
||||
return [stdoutStream, cloudwatchStream]
|
||||
}
|
||||
|
||||
function createLogger(name, env = NODE_ENV) {
|
||||
const childLogs = new Map()
|
||||
const logger = bunyan.createLogger({
|
||||
name,
|
||||
env,
|
||||
serializers: bunyan.stdSerializers,
|
||||
streams: getLogStreams(name, env),
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue