Skip to content

Commit

Permalink
Fixes #332, the EventEmitter memory leak warning
Browse files Browse the repository at this point in the history
The bug was due to reusing transports when creating new loggers.
Also upgrades to winston 3.1.0 which fixes a different EventEmitter issue
which results in the same warning.
  • Loading branch information
aneilbaboo committed Nov 29, 2018
1 parent c19b467 commit 4d838a7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"seqvarnomjs": "git+ssh://git@github.com/precisely/seqvarnomjs#1.3.3",
"slugify": "^1.3.0",
"smart-report": "git+ssh://git@github.com/precisely/smart-report.git#2.0.8",
"winston": "^3.0.0",
"winston": "^3.1.0",
"winston-cloudwatch": "^2.0.2"
},
"devDependencies": {
Expand Down
33 changes: 18 additions & 15 deletions app-backend/src/common/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,11 @@ const { format } = winston;
const WinstonCloudWatch = require('winston-cloudwatch');

export const LOG_DATA_SEP = '\t|\t';
import * as fs from 'fs';

type FormatInfo = { timestamp: number, level: number | string, message: string };
const shouldLogToCloudWatchAggregate = process.env.STAGE !== 'prod' && !isOffline;
const LOG_LEVEL = (process.env.LOG_LEVEL || 'info').toLowerCase();
const LOG_TRANSPORTS = shouldLogToCloudWatchAggregate ? [
new winston.transports.Console(),

// Adds Cloudwatch logging at
// /precisely/web/{stage}/aggregated-log
new WinstonCloudWatch({ // aggregate view across all lambda fns
level: LOG_LEVEL,
logGroupName: `/precisely/web/${process.env.STAGE}`,
logStreamName: 'aggregated-log'
})
] : [
new winston.transports.Console()
];

function makeFormatter(colorize: boolean, requestId?: string) {
const plugins = [ format.timestamp(), format.splat() ];
Expand All @@ -46,7 +34,6 @@ function makeFormatter(colorize: boolean, requestId?: string) {
(info: FormatInfo) => `${info.timestamp} ${info.level}: ${info.message}${LOG_DATA_SEP}`)
);
}

return format.combine(... plugins);
}

Expand All @@ -69,10 +56,26 @@ export interface Logger {
shouldLog(level: number | string): boolean;
}

function makeTransports() {
return shouldLogToCloudWatchAggregate ? [
new winston.transports.Console(),

// Adds Cloudwatch logging at
// /precisely/web/{stage}/aggregated-log
new WinstonCloudWatch({ // aggregate view across all lambda fns
level: LOG_LEVEL,
logGroupName: `/precisely/web/${process.env.STAGE}`,
logStreamName: 'aggregated-log'
})
] : [
new winston.transports.Console()
];
}

export function makeLogger(requestId?: string): Logger {
const shouldColorize = isOffline;
const logger = winston.createLogger({
transports: LOG_TRANSPORTS,
transports: makeTransports(),
level: LOG_LEVEL,
format: makeFormatter(shouldColorize, requestId)
});
Expand Down
21 changes: 18 additions & 3 deletions app-backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ async-limiter@~1.0.0:

async@1.x, async@^1.5.2:
version "1.5.2"
resolved "http://registry.npmjs.org/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=

async@2.5.0:
Expand Down Expand Up @@ -4714,6 +4714,21 @@ istanbul@^0.4.5:
version "0.4.5"
resolved "https://registry.yarnpkg.com/istanbul/-/istanbul-0.4.5.tgz#65c7d73d4c4da84d4f3ac310b918fb0b8033733b"
integrity sha1-ZcfXPUxNqE1POsMQuRj7C4Azczs=
dependencies:
abbrev "1.0.x"
async "1.x"
escodegen "1.8.x"
esprima "2.7.x"
glob "^5.0.15"
handlebars "^4.0.1"
js-yaml "3.x"
mkdirp "0.5.x"
nopt "3.x"
once "1.x"
resolve "1.1.x"
supports-color "^3.1.0"
which "^1.1.1"
wordwrap "^1.0.0"

isurl@^1.0.0-alpha5:
version "1.0.0"
Expand Down Expand Up @@ -6019,7 +6034,7 @@ mixin-deep@^1.2.0:

mkdirp@0.5.x, mkdirp@0.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
version "0.5.1"
resolved "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
dependencies:
minimist "0.0.8"
Expand Down Expand Up @@ -9224,7 +9239,7 @@ winston-transport@^4.2.0:
readable-stream "^2.3.6"
triple-beam "^1.2.0"

winston@^3.0.0:
winston@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/winston/-/winston-3.1.0.tgz#80724376aef164e024f316100d5b178d78ac5331"
integrity sha512-FsQfEE+8YIEeuZEYhHDk5cILo1HOcWkGwvoidLrDgPog0r4bser1lEIOco2dN9zpDJ1M88hfDgZvxe5z4xNcwg==
Expand Down

0 comments on commit 4d838a7

Please sign in to comment.