1 define(function(require) {
4 /* global describe, it, beforeEach */
5 var chai = require('libs/chai'),
6 logging = require('./logging.js'),
10 // Global log object for defining expectations
16 append: function(msg) {
19 contains: function(msg) {
20 return this._msgs.indexOf(msg) !== -1;
23 return this._msgs.length ? this._msgs[this._msgs.length] : undefined;
26 return this._msgs.length === 0;
28 getMessages: function() {
33 // Loggin handler that just writes to the global logger object
34 var testLoggingHandler = function(msg) {
38 describe('Logging', function() {
41 beforeEach(function() {
43 logging.clearConfig();
46 var setConfig = function(loggerLevel, handlerLevel) {
50 handler: testLoggingHandler,
57 handlers: ['testHandler']
63 it('works with sample config', function() {
64 setConfig('debug', 'debug');
65 var logger = logging.getLogger('some.name');
66 logger.debug('debug msg');
67 expect(log.contains('debug msg')).to.equal(true);
70 it('filters level on loggers', function() {
71 setConfig('info', 'debug');
72 var logger = logging.getLogger('some.name');
73 logger.debug('debug msg');
74 expect(log.isEmpty()).to.equal(true, 'debug message filtered out');
75 logger.info('info msg');
76 expect(log.contains('info msg')).to.equal(true, 'info message passed');
79 it('filters level on handlers', function() {
80 setConfig('debug', 'info');
81 var logger = logging.getLogger('some.name');
82 logger.debug('debug msg');
83 expect(log.isEmpty()).to.equal(true, 'debug message filtered out');
84 logger.info('info msg');
85 expect(log.contains('info msg')).to.equal(true, 'info message passed');
88 it('propagates message to upper logger depending on the propagate flag', function() {
92 handler: testLoggingHandler,
99 handlers: ['testHandler']
103 handlers: ['testHandler']
109 config.loggers.logger1.propagate = false;
110 logging.setConfig(config);
112 logger = logging.getLogger('logger1');
114 logger.debug('msg1');
115 expect(log.contains('msg1')).to.equal(true, 'first message logged');
116 expect(log.getMessages().length === 1).to.equal(true, 'logger didn\'t propagate its message');
119 config.loggers.logger1.propagate = true;
120 logging.setConfig(config);
122 logger.debug('msg2');
123 expect(log.contains('msg2')).to.equal(true, 'second message logged');
124 expect(log.getMessages().length === 2).to.equal(true, 'second message propagated to upper logger');