Merge branch 'master' into util.format
This commit is contained in:
@@ -115,11 +115,11 @@ function createAppender(config) {
|
||||
}
|
||||
}
|
||||
|
||||
function configure(config) {
|
||||
function configure(config, options) {
|
||||
var actualAppender;
|
||||
if (config.appender && config.mode === 'master') {
|
||||
log4js.loadAppender(config.appender.type);
|
||||
actualAppender = log4js.appenderMakers[config.appender.type](config.appender);
|
||||
actualAppender = log4js.appenderMakers[config.appender.type](config.appender, options);
|
||||
config.actualAppender = actualAppender;
|
||||
}
|
||||
return createAppender(config);
|
||||
|
||||
@@ -10,8 +10,9 @@ var dateFormat = require('./date_format')
|
||||
, "coloured": function() { return colouredLayout; }
|
||||
, "pattern": function (config) {
|
||||
var pattern = config.pattern || undefined;
|
||||
return patternLayout(pattern);
|
||||
}
|
||||
var tokens = config.tokens || undefined;
|
||||
return patternLayout(pattern, tokens);
|
||||
}
|
||||
}
|
||||
, colours = {
|
||||
ALL: "grey"
|
||||
@@ -121,13 +122,26 @@ function messagePassThroughLayout (loggingEvent) {
|
||||
* - %d date in various formats
|
||||
* - %% %
|
||||
* - %n newline
|
||||
* - %x{<tokenname>} add dynamic tokens to your log. Tokens are specified in the tokens parameter
|
||||
* You can use %[ and %] to define a colored block.
|
||||
* Takes a pattern string and returns a layout function.
|
||||
*
|
||||
* Tokens are specified as simple key:value objects.
|
||||
* The key represents the token name whereas the value can be a string or function
|
||||
* which is called to extract the value to put in the log message. If token is not
|
||||
* found, it doesn't replace the field.
|
||||
*
|
||||
* A sample token would be: { "pid" : function() { return process.pid; } }
|
||||
*
|
||||
* Takes a pattern string, array of tokens and returns a layout function.
|
||||
* @param {String} Log format pattern String
|
||||
* @param {object} map object of different tokens
|
||||
* @return {Function}
|
||||
* @author Stephan Strittmatter
|
||||
* @author Jan Schmidle
|
||||
*/
|
||||
function patternLayout (pattern) {
|
||||
function patternLayout (pattern, tokens) {
|
||||
var TTCC_CONVERSION_PATTERN = "%r %p %c - %m%n";
|
||||
var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([\[\]cdmnpr%])(\{([^\}]+)\})?|([^%]+)/;
|
||||
var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([\[\]cdmnprx%])(\{([^\}]+)\})?|([^%]+)/;
|
||||
|
||||
pattern = pattern || TTCC_CONVERSION_PATTERN;
|
||||
|
||||
@@ -203,6 +217,17 @@ function patternLayout (pattern) {
|
||||
case "%":
|
||||
replacement = "%";
|
||||
break;
|
||||
case "x":
|
||||
if(typeof(tokens[specifier]) !== 'undefined') {
|
||||
if(typeof(tokens[specifier]) === 'function') {
|
||||
replacement = tokens[specifier]();
|
||||
} else {
|
||||
replacement = tokens[specifier];
|
||||
}
|
||||
} else {
|
||||
replacement = matchedString;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
replacement = matchedString;
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var events = require('events'),
|
||||
Dequeue = require('dequeue'),
|
||||
util = require('util');
|
||||
|
||||
module.exports = BufferedWriteStream;
|
||||
@@ -6,7 +7,7 @@ module.exports = BufferedWriteStream;
|
||||
function BufferedWriteStream(stream) {
|
||||
var that = this;
|
||||
this.stream = stream;
|
||||
this.buffer = [];
|
||||
this.buffer = new Dequeue();
|
||||
this.canWrite = false;
|
||||
this.bytes = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user