Skip to content

Commit

Permalink
Fixes linting error, allows for merged options in transport functions…
Browse files Browse the repository at this point in the history
…, and fixes wrong prop name in hasTransport
  • Loading branch information
rhyslbw committed Apr 27, 2016
1 parent 05e7187 commit 92ba9cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
24 changes: 12 additions & 12 deletions source/server/module.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
Space.Module.define('Space.logging.Winston', {
Space.Module.define('Space.logging.Winston', {

dependencies: {
configuration: 'configuration',
log: 'Space.Logger',
log: 'Space.Logger'
},

onInitialize() {
let log = this.injector.get('log');
const log = this.injector.get('log');

let transports = lodash.get(this.configuration, 'log.winston.transports', [
const transports = lodash.get(this.configuration, 'log.winston.transports', [
this._setupWinstonConsoleTransport()
])
let adapter = new Space.Logger.WinstonAdapter(transports);
]);
const adapter = new Space.Logger.WinstonAdapter(transports);
this.injector.map('Space.Logger.WinstonAdapter').toStaticValue(adapter);
log.addAdapter('winston', adapter);
},

_setupWinstonConsoleTransport() {
options = {
_setupWinstonConsoleTransport(options) {
const mergedOptions = _.extend({}, {
colorize: true,
prettyPrint: true,
level: 'info',
}
return Space.Logger.WinstonAdapter.console(options);
level: 'info'
}, options);
return Space.Logger.WinstonAdapter.console(mergedOptions);
}
});
});
24 changes: 11 additions & 13 deletions source/server/winston-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const winston = Npm.require('winston');
const WinstonAdapter = Space.Logger.Adapter.extend('Space.Logger.WinstonAdapter', {

Constructor(transports) {
let lib = new winston.Logger({
const lib = new winston.Logger({
transports: transports || []
});
lib.setLevels(winston.config.syslog.levels);
Expand All @@ -18,15 +18,15 @@ const WinstonAdapter = Space.Logger.Adapter.extend('Space.Logger.WinstonAdapter'
return this._lib.remove.apply(this._lib, arguments);
},

hasTransport(name) {
return this._lib.transports[transportName] != null;
hasTransport(transportName) {
return this._lib.transports[transportName] !== null;
},

setLevel(transportName, levelName) {
if (!this.hasTransport(transportName)) {
throw new Error(this.ERRORS.transportNotAdded(transportName));
}
return this._lib.transports[transportName].level = levelName;
this._lib.transports[transportName].level = levelName;
},

ERRORS: {
Expand All @@ -36,13 +36,11 @@ const WinstonAdapter = Space.Logger.Adapter.extend('Space.Logger.WinstonAdapter'
}
});

WinstonAdapter.console = function(options) {
if (options == null) {
let options = {
colorize: true,
prettyPrint: true,
level: 'info'
};
}
return new winston.transports.Console(options);
WinstonAdapter.console = (options) => {
const mergedOptions = _.extend({}, {
colorize: true,
prettyPrint: true,
level: 'info'
}, options);
return new winston.transports.Console(mergedOptions);
};

0 comments on commit 92ba9cb

Please sign in to comment.