2014-12-15 07:21:28 +08:00
|
|
|
"use strict";
|
2014-05-25 01:34:19 +08:00
|
|
|
|
2015-06-09 22:21:03 +08:00
|
|
|
var Logger = lib("logger"),
|
2015-07-14 04:55:42 +08:00
|
|
|
Config = lib("config");
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-12-15 07:21:28 +08:00
|
|
|
describe("Logger", function() {
|
2014-07-05 00:49:29 +08:00
|
|
|
afterEach(function() {
|
2014-10-29 06:53:03 +08:00
|
|
|
// to be friendly to other specs
|
2015-07-14 04:55:42 +08:00
|
|
|
Config.logger = false;
|
2015-09-02 01:18:17 +08:00
|
|
|
Config.silent = false;
|
2014-10-29 06:53:03 +08:00
|
|
|
Logger.setup();
|
2013-10-25 05:25:42 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 07:15:13 +08:00
|
|
|
describe("#setup", function() {
|
|
|
|
context("with no arguments", function() {
|
|
|
|
it("sets up a BasicLogger", function() {
|
2015-07-14 04:55:42 +08:00
|
|
|
Config.logger = null;
|
2014-03-22 07:15:13 +08:00
|
|
|
Logger.setup();
|
2015-07-14 04:55:42 +08:00
|
|
|
expect(Logger.logger.name).to.be.eql("basiclogger");
|
2014-03-22 07:15:13 +08:00
|
|
|
});
|
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
|
2014-03-22 07:15:13 +08:00
|
|
|
context("with false", function() {
|
|
|
|
it("sets up a NullLogger", function() {
|
2015-07-14 04:55:42 +08:00
|
|
|
Config.logger = false;
|
2014-10-29 06:53:03 +08:00
|
|
|
Logger.setup();
|
2015-07-14 04:55:42 +08:00
|
|
|
expect(Logger.logger.name).to.be.eql("nulllogger");
|
2014-03-22 07:15:13 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
context("with a custom logger", function() {
|
|
|
|
it("uses the custom logger", function() {
|
2015-07-14 04:55:42 +08:00
|
|
|
function customlogger() {}
|
|
|
|
Config.logger = customlogger;
|
2014-10-29 06:53:03 +08:00
|
|
|
Logger.setup();
|
2015-07-14 04:55:42 +08:00
|
|
|
expect(Logger.logger.name).to.be.eql("customlogger");
|
2014-11-29 01:37:44 +08:00
|
|
|
});
|
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 07:15:13 +08:00
|
|
|
describe("proxies", function() {
|
2014-07-05 00:49:29 +08:00
|
|
|
var logger;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2015-07-14 04:55:42 +08:00
|
|
|
logger = spy();
|
|
|
|
Logger.logger = logger;
|
2014-03-22 07:15:13 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("#debug", function() {
|
2015-07-14 04:55:42 +08:00
|
|
|
it("proxies to the logger method", function() {
|
|
|
|
Logger.should.debug = true;
|
|
|
|
Logger.debug("debug message");
|
|
|
|
Logger.should.debug = false;
|
|
|
|
expect(logger).to.be.calledWith("debug message");
|
2014-03-22 07:15:13 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-07-14 04:55:42 +08:00
|
|
|
describe("#log", function() {
|
|
|
|
it("proxies to the logger method", function() {
|
|
|
|
Logger.log("log message");
|
|
|
|
expect(logger).to.be.calledWith("log message");
|
2014-03-22 07:15:13 +08:00
|
|
|
});
|
|
|
|
});
|
2014-10-27 23:59:36 +08:00
|
|
|
});
|
2015-06-23 10:08:15 +08:00
|
|
|
|
|
|
|
it("automatically updates if configuration changed", function() {
|
|
|
|
var custom = spy();
|
2015-07-14 04:55:42 +08:00
|
|
|
expect(Logger.logger.name).to.be.eql("basiclogger");
|
|
|
|
Config.update({ logger: custom });
|
2015-06-23 10:08:15 +08:00
|
|
|
expect(Logger.logger).to.be.eql(custom);
|
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|