From 9121f9014a97dc8e311091c01a4d56c4f4ee9a42 Mon Sep 17 00:00:00 2001 From: Steve Jones Date: Mon, 26 Nov 2018 12:44:14 -0500 Subject: [PATCH 1/2] Configure winston only once Moves winston configuration into body of logger factory -- winston was being re-configured after every middleware pipeline invocation, resulting in memory leaks and duplicate log output. --- src/logging.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/logging.ts b/src/logging.ts index a790859..84847ed 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -2,7 +2,22 @@ import * as Koa from 'koa'; import { config } from './config'; import * as winston from 'winston'; -export function logger(winstonInstance) { +export function logger(winstonInstance) { + winstonInstance.configure({ + level: config.debugLogging ? 'debug' : 'info', + transports: [ + // + // - Write all logs error (and below) to `error.log`. + new winston.transports.File({ filename: 'error.log', level: 'error' }), + // + // - Write to all logs with specified level to console. + new winston.transports.Console({ format: winston.format.combine( + winston.format.colorize(), + winston.format.simple() + ) }) + ] + }); + return async(ctx: Koa.Context, next: () => Promise) => { const start = new Date().getMilliseconds(); @@ -24,21 +39,6 @@ export function logger(winstonInstance) { const msg: string = `${ctx.method} ${ctx.originalUrl} ${ctx.status} ${ms}ms`; - winstonInstance.configure({ - level: config.debugLogging ? 'debug' : 'info', - transports: [ - // - // - Write all logs error (and below) to `error.log`. - new winston.transports.File({ filename: 'error.log', level: 'error' }), - // - // - Write to all logs with specified level to console. - new winston.transports.Console({ format: winston.format.combine( - winston.format.colorize(), - winston.format.simple() - ) }) - ] - }); - winstonInstance.log(logLevel, msg); }; -} \ No newline at end of file +} From ac7865c9d63d9084287f2f4aa9ed347829916354 Mon Sep 17 00:00:00 2001 From: Javier Aviles Date: Tue, 27 Nov 2018 14:31:42 +0100 Subject: [PATCH 2/2] Removing trailing whitespace --- src/logging.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logging.ts b/src/logging.ts index 84847ed..925fa7a 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -2,7 +2,7 @@ import * as Koa from 'koa'; import { config } from './config'; import * as winston from 'winston'; -export function logger(winstonInstance) { +export function logger(winstonInstance) { winstonInstance.configure({ level: config.debugLogging ? 'debug' : 'info', transports: [