added cluster identifier support

This commit is contained in:
Christophe Bol 2014-12-01 12:29:45 +01:00
parent ec5f4485f8
commit b694fd1d8d
2 changed files with 30 additions and 3 deletions

View File

@ -87,6 +87,15 @@ function createAppender(config) {
// console.log("master : " + cluster.isMaster + " received message: " + JSON.stringify(message.event)); // console.log("master : " + cluster.isMaster + " received message: " + JSON.stringify(message.event));
var loggingEvent = deserializeLoggingEvent(message.event); var loggingEvent = deserializeLoggingEvent(message.event);
// Adding PID metadata
loggingEvent.pid = worker.process.pid;
loggingEvent.cluster = {
master: process.pid,
worker: worker.process.pid,
workerId: worker.id
};
masterAppender(loggingEvent); masterAppender(loggingEvent);
} }
}); });

View File

@ -145,7 +145,7 @@ function messagePassThroughLayout (loggingEvent) {
*/ */
function patternLayout (pattern, tokens) { function patternLayout (pattern, tokens) {
var TTCC_CONVERSION_PATTERN = "%r %p %c - %m%n"; var TTCC_CONVERSION_PATTERN = "%r %p %c - %m%n";
var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([\[\]cdhmnprzx%])(\{([^\}]+)\})?|([^%]+)/; var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([\[\]cdhmnprzxy%])(\{([^\}]+)\})?|([^%]+)/;
pattern = pattern || TTCC_CONVERSION_PATTERN; pattern = pattern || TTCC_CONVERSION_PATTERN;
@ -212,8 +212,25 @@ function patternLayout (pattern, tokens) {
return '%'; return '%';
} }
function pid() { function pid(loggingEvent) {
return process.pid; if (loggingEvent.pid) {
return loggingEvent.pid;
} else {
return process.pid;
}
}
function clusterInfo(loggingEvent, specifier) {
if (loggingEvent.cluster && specifier) {
return specifier
.replace('%m', loggingEvent.cluster.master)
.replace('%w', loggingEvent.cluster.worker)
.replace('%i', loggingEvent.cluster.workerId);
} else if (loggingEvent.cluster) {
return loggingEvent.cluster.worker+'@'+loggingEvent.cluster.master;
} else {
return pid();
}
} }
function userDefined(loggingEvent, specifier) { function userDefined(loggingEvent, specifier) {
@ -237,6 +254,7 @@ function patternLayout (pattern, tokens) {
'r': startTime, 'r': startTime,
'[': startColour, '[': startColour,
']': endColour, ']': endColour,
'y': clusterInfo,
'z': pid, 'z': pid,
'%': percent, '%': percent,
'x': userDefined 'x': userDefined