Skip to content

Commit

Permalink
Minor bugfix. Transports can be added independently
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitor Magán García committed Oct 3, 2013
1 parent 95299f9 commit 7dd4d22
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,17 @@ function createWinston(cfg) {

winstonLogger = new (winston.Logger)({
level: cfg.logLevel,
exitOnError: exitOnError,
transports: [
new (winston.transports.Console)(cfg.Console),
new (winston.transports.File)(cfg.File)
]
exitOnError: exitOnError
});

if (cfg.Console) {
winstonLogger.add(winston.transports.Console, cfg.Console);
}

if (cfg.File) {
winstonLogger.add(winston.transports.File, cfg.File);
}

winstonLogger.setLevels(winston.config.syslog.levels);

}
Expand All @@ -168,7 +172,12 @@ function setConfig(newCfg) {
"use strict";

config = newCfg;
config.File.handleExceptions = true; //Necessary to handle file exceptions

//Only when Transport File is going to be used.
if (config.File) {
config.File.handleExceptions = true; //Necessary to handle file exceptions
}

createWinston(config);

}
Expand Down Expand Up @@ -198,7 +207,7 @@ function newLogger() {
var message = createLogMessage.call(this, level, message, logObj).replace(/\n/g, '');

var tmpLogger = winstonLogger.log(level, message);
if (config.flushEachMessage && tmpLogger.transports.file._stream)
if (config.flushEachMessage && tmpLogger.transports.file && tmpLogger.transports.file._stream)
tmpLogger.transports.file.flush();
return tmpLogger;
};
Expand Down

0 comments on commit 7dd4d22

Please sign in to comment.