moved level colours into layouts where they belong, updated README

This commit is contained in:
Gareth Jones
2011-07-13 18:29:53 +10:00
parent 5868856a7d
commit d7ffa59434
4 changed files with 33 additions and 28 deletions

View File

@@ -2,16 +2,27 @@ var dateFormat = require('./date_format')
, util = require('util')
, replacementRegExp = /%[sdj]/g
, layoutMakers = {
"messagePassThrough": function() { return messagePassThroughLayout; },
"basic": function() { return basicLayout; },
"colored": function() { return colouredLayout; },
"coloured": function() { return colouredLayout; },
"pattern": function (config) {
"messagePassThrough": function() { return messagePassThroughLayout; }
, "basic": function() { return basicLayout; }
, "colored": function() { return colouredLayout; }
, "coloured": function() { return colouredLayout; }
, "pattern": function (config) {
var pattern = config.pattern || undefined;
return patternLayout(pattern);
}
}
, colours = {
ALL: "grey"
, TRACE: "blue"
, DEBUG: "cyan"
, INFO: "green"
, WARN: "yellow"
, ERROR: "red"
, FATAL: "magenta"
, OFF: "grey"
};
function formatLogData(logData) {
var output = ""
, data = Array.isArray(logData) ? logData.slice() : Array.prototype.slice.call(arguments)
@@ -100,7 +111,7 @@ function basicLayout (loggingEvent) {
* same as basicLayout, but with colours.
*/
function colouredLayout (loggingEvent) {
return timestampLevelAndCategory(loggingEvent, loggingEvent.level.colour) + formatLogData(loggingEvent.data);
return timestampLevelAndCategory(loggingEvent, colours[loggingEvent.level.toString()]) + formatLogData(loggingEvent.data);
}
function messagePassThroughLayout (loggingEvent) {

View File

@@ -1,7 +1,6 @@
function Level(level, levelStr, colour) {
function Level(level, levelStr) {
this.level = level;
this.levelStr = levelStr;
this.colour = colour;
}
/**
@@ -45,13 +44,13 @@ Level.prototype.isGreaterThanOrEqualTo = function(otherLevel) {
};
module.exports = {
ALL: new Level(Number.MIN_VALUE, "ALL", "grey")
, TRACE: new Level(5000, "TRACE", "blue")
, DEBUG: new Level(10000, "DEBUG", "cyan")
, INFO: new Level(20000, "INFO", "green")
, WARN: new Level(30000, "WARN", "yellow")
, ERROR: new Level(40000, "ERROR", "red")
, FATAL: new Level(50000, "FATAL", "magenta")
, OFF: new Level(Number.MAX_VALUE, "OFF", "grey")
ALL: new Level(Number.MIN_VALUE, "ALL")
, TRACE: new Level(5000, "TRACE")
, DEBUG: new Level(10000, "DEBUG")
, INFO: new Level(20000, "INFO")
, WARN: new Level(30000, "WARN")
, ERROR: new Level(40000, "ERROR")
, FATAL: new Level(50000, "FATAL")
, OFF: new Level(Number.MAX_VALUE, "OFF")
, toLevel: toLevel
};