1 define(function(require) {
5 var _ = require('libs/underscore'),
6 handlers = require('fnpjs/logging/handlers'),
8 levels = ['debug', 'info', 'warning', 'error', 'critical'];
11 var Logger = function(name) {
13 Object.defineProperty(this, 'config', {
19 }, config.loggers[name] || {});
24 _.extend(Logger.prototype, {
25 log: function(level, message, data) {
26 if(levels.indexOf(level) !== -1 && levels.indexOf(level) >= levels.indexOf(this.config.level)) {
27 this.config.handlers.forEach(function(handlerName) {
28 var handlerConfig = config.handlers[handlerName],
29 handler = handlerConfig.handler,
30 handlerLevel = handlerConfig.level || 'info';
32 if(typeof handler === 'string') {
33 handler = handlers[handlerConfig.handler];
36 throw new Error('Unknown handler: ' + handlerName);
39 if(levels.indexOf(handlerLevel) !== -1 && levels.indexOf(level) >= levels.indexOf(handlerLevel)) {
43 loggerName: this.name,
49 if(this.config.propagate && this.name) {
50 var logger = new Logger(this.name.split('.').slice(0, -1).join('.'));
51 logger.log(level, message, data);
54 exception: function(e) {
55 this.log('error', e.toString(), {exception: e});
59 levels.forEach(function(level) {
60 Logger.prototype[level] = function(message, data) {
61 return this.log(level, message, data);
67 getLogger: function(name) {
68 return new Logger(name);
70 setConfig: function(_config) {
76 clearConfig: function() {