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)) {
40 handler(message, level, data);
44 if(this.config.propagate && this.name) {
45 var logger = new Logger(this.name.split('.').slice(0, -1).join('.'));
46 logger.log(level, message, data);
49 exception: function(e) {
50 this.log('error', e.toString(), {exception: e});
54 levels.forEach(function(level) {
55 Logger.prototype[level] = function(message, data) {
56 return this.log(level, message, data);
62 getLogger: function(name) {
63 return new Logger(name);
65 setConfig: function(_config) {
71 clearConfig: function() {