more linting
This commit is contained in:
parent
516320c79a
commit
46ae1a586d
@ -1,7 +1,8 @@
|
|||||||
var levels = require('./levels'),
|
"use strict";
|
||||||
util = require('util'),
|
var levels = require('./levels')
|
||||||
events = require('events'),
|
, util = require('util')
|
||||||
DEFAULT_CATEGORY = '[default]';
|
, events = require('events')
|
||||||
|
, DEFAULT_CATEGORY = '[default]';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models a logging event.
|
* Models a logging event.
|
||||||
@ -13,11 +14,11 @@ var levels = require('./levels'),
|
|||||||
* @author Seth Chisamore
|
* @author Seth Chisamore
|
||||||
*/
|
*/
|
||||||
function LoggingEvent (categoryName, level, data, logger) {
|
function LoggingEvent (categoryName, level, data, logger) {
|
||||||
this.startTime = new Date();
|
this.startTime = new Date();
|
||||||
this.categoryName = categoryName;
|
this.categoryName = categoryName;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,49 +29,50 @@ function LoggingEvent (categoryName, level, data, logger) {
|
|||||||
* @author Stephan Strittmatter
|
* @author Stephan Strittmatter
|
||||||
*/
|
*/
|
||||||
function Logger (name, level) {
|
function Logger (name, level) {
|
||||||
this.category = name || DEFAULT_CATEGORY;
|
this.category = name || DEFAULT_CATEGORY;
|
||||||
|
|
||||||
if (! this.level) {
|
if (level) {
|
||||||
this.__proto__.level = levels.TRACE;
|
this.setLevel(level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
util.inherits(Logger, events.EventEmitter);
|
util.inherits(Logger, events.EventEmitter);
|
||||||
Logger.DEFAULT_CATEGORY = DEFAULT_CATEGORY;
|
Logger.DEFAULT_CATEGORY = DEFAULT_CATEGORY;
|
||||||
|
Logger.prototype.level = levels.TRACE;
|
||||||
|
|
||||||
Logger.prototype.setLevel = function(level) {
|
Logger.prototype.setLevel = function(level) {
|
||||||
this.level = levels.toLevel(level, this.level || levels.TRACE);
|
this.level = levels.toLevel(level, this.level || levels.TRACE);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.removeLevel = function() {
|
Logger.prototype.removeLevel = function() {
|
||||||
delete this.level;
|
delete this.level;
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.log = function() {
|
Logger.prototype.log = function() {
|
||||||
var args = Array.prototype.slice.call(arguments)
|
var args = Array.prototype.slice.call(arguments)
|
||||||
, logLevel = args.shift()
|
, logLevel = args.shift()
|
||||||
, loggingEvent = new LoggingEvent(this.category, logLevel, args, this);
|
, loggingEvent = new LoggingEvent(this.category, logLevel, args, this);
|
||||||
this.emit("log", loggingEvent);
|
this.emit("log", loggingEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.isLevelEnabled = function(otherLevel) {
|
Logger.prototype.isLevelEnabled = function(otherLevel) {
|
||||||
return this.level.isLessThanOrEqualTo(otherLevel);
|
return this.level.isLessThanOrEqualTo(otherLevel);
|
||||||
};
|
};
|
||||||
|
|
||||||
['Trace','Debug','Info','Warn','Error','Fatal'].forEach(
|
['Trace','Debug','Info','Warn','Error','Fatal'].forEach(
|
||||||
function(levelString) {
|
function(levelString) {
|
||||||
var level = levels.toLevel(levelString);
|
var level = levels.toLevel(levelString);
|
||||||
Logger.prototype['is'+levelString+'Enabled'] = function() {
|
Logger.prototype['is'+levelString+'Enabled'] = function() {
|
||||||
return this.isLevelEnabled(level);
|
return this.isLevelEnabled(level);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype[levelString.toLowerCase()] = function () {
|
Logger.prototype[levelString.toLowerCase()] = function () {
|
||||||
if (this.isLevelEnabled(level)) {
|
if (this.isLevelEnabled(level)) {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
args.unshift(level);
|
args.unshift(level);
|
||||||
Logger.prototype.log.apply(this, args);
|
Logger.prototype.log.apply(this, args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user