-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Space.Module.define('Space.logging.Winston', { | ||
|
||
dependencies: { | ||
configuration: 'configuration', | ||
log: 'Space.Logger', | ||
}, | ||
|
||
onInitialize() { | ||
let log = this.injector.get('log'); | ||
|
||
let transports = lodash.get(this.configuration, 'log.winston.transports', [ | ||
this._setupWinstonConsoleTransport() | ||
]) | ||
let adapter = new Space.Logger.WinstonAdapter(transports); | ||
this.injector.map('Space.Logger.WinstonAdapter').toStaticValue(adapter); | ||
log.addAdapter('winston', adapter); | ||
}, | ||
|
||
_setupWinstonConsoleTransport() { | ||
options = { | ||
colorize: true, | ||
prettyPrint: true, | ||
level: 'info', | ||
} | ||
return Space.Logger.WinstonAdapter.console(options); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const winston = Npm.require('winston'); | ||
|
||
const WinstonAdapter = Space.Logger.Adapter.extend('Space.Logger.WinstonAdapter', { | ||
|
||
Constructor: function(transports) { | ||
let lib = new winston.Logger({ | ||
transports: transports || [] | ||
}); | ||
lib.setLevels(winston.config.syslog.levels); | ||
this.setLib(lib); | ||
}, | ||
|
||
addTransport: function() { | ||
return this._lib.add.apply(this._lib, arguments); | ||
}, | ||
|
||
removeTransport: function() { | ||
return this._lib.remove.apply(this._lib, arguments); | ||
}, | ||
|
||
hasTransport: function(name) { | ||
return this._lib.transports[transportName] != null; | ||
}, | ||
|
||
setMinLevel: function(transportName, levelName) { | ||
if (!this.hasTransport(transportName)) { | ||
throw new Error(this.ERRORS.transportNotAdded(transportName)); | ||
} | ||
return this._lib.transports[transportName].level = levelName; | ||
}, | ||
|
||
ERRORS: { | ||
transportNotAdded: function(transportName) { | ||
return `Winston transport with ${transportName} is not added`; | ||
} | ||
} | ||
}); | ||
|
||
WinstonAdapter.console = function(options) { | ||
if (options == null) { | ||
let options = { | ||
colorize: true, | ||
prettyPrint: true, | ||
level: 'info' | ||
}; | ||
} | ||
return new winston.transports.Console(options); | ||
}; |