Skip to content

Commit

Permalink
fix(logger): fix re-instantiation of winston loggers on method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal committed Aug 26, 2017
1 parent e7a8b9e commit b6056fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/lib/services/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
var config = require('../config'),
express = require('express'),
logger = require('./logger').log(),
log = require('./logger').log(),
expressLogger = require('./logger').logExpress(),
bodyParser = require('body-parser'),
session = require('express-session'),
Expand Down
18 changes: 15 additions & 3 deletions server/lib/services/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ const fs = require('fs');
const winston = require('winston');
const winstonExpress = require('express-winston');

// maintain variables for singleton
let logger;
let loggerExpress;

module.exports = class Logger {
static log() {
if (logger) {
return logger;
}

// Instantiating the default winston application logger with the Console transport
const logger = new winston.Logger({
logger = new winston.Logger({
transports: [
new winston.transports.Console({
level: 'info',
Expand Down Expand Up @@ -72,7 +80,11 @@ module.exports = class Logger {
* use with express logger
*/
static logExpress() {
const logger = winstonExpress.logger({
if (loggerExpress) {
return loggerExpress;
}

loggerExpress = winstonExpress.logger({
transports: [
new winston.transports.Console({
level: 'info',
Expand All @@ -85,6 +97,6 @@ module.exports = class Logger {
colorize: true
});

return logger;
return loggerExpress;
}
}

0 comments on commit b6056fb

Please sign in to comment.