Support passing config to Logger#setup again

This commit is contained in:
Andrew Stewart 2014-11-28 09:37:44 -08:00
parent 83153664f5
commit 4f850d5e9e
2 changed files with 16 additions and 1 deletions

View File

@ -28,7 +28,13 @@ var Logger = module.exports = {};
// or above // or above
// //
// Returns the new logger instance // Returns the new logger instance
Logger.setup = function setup() { Logger.setup = function setup(opts) {
var Cylon = require('./cylon');
if (typeof opts === 'object') {
Cylon.config({ logging: opts });
}
var logger = Config.logging.logger, var logger = Config.logging.logger,
level = Config.logging.level || "info"; level = Config.logging.level || "info";

View File

@ -36,6 +36,15 @@ describe('Logger', function() {
expect(Logger.toString()).to.be.eql("custom"); expect(Logger.toString()).to.be.eql("custom");
}); });
}); });
context("with a custom logger, provided directly", function() {
it("uses the custom logger", function() {
var logger = { toString: function() { return "custom"; } };
Logger.setup({ logger: logger });
expect(Logger.toString()).to.be.eql("custom");
expect(Config.logging.logger).to.be.eql(logger);
});
});
}); });
describe("proxies", function() { describe("proxies", function() {