Skip to content

Commit

Permalink
Merge pull request #32 from steve-a-jones/logger-fix
Browse files Browse the repository at this point in the history
Logger fix
  • Loading branch information
javieraviles authored Nov 27, 2018
2 parents bbebc29 + ac7865c commit 7bfc27e
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ import { config } from './config';
import * as winston from 'winston';

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<any>) => {

const start = new Date().getMilliseconds();
Expand All @@ -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);
};
}
}

0 comments on commit 7bfc27e

Please sign in to comment.