diff --git a/lib/appenders/clustered.js b/lib/appenders/clustered.js index b427ab6..7c31248 100755 --- a/lib/appenders/clustered.js +++ b/lib/appenders/clustered.js @@ -87,6 +87,15 @@ function createAppender(config) { // console.log("master : " + cluster.isMaster + " received message: " + JSON.stringify(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); } }); diff --git a/lib/layouts.js b/lib/layouts.js index 270f336..be5681c 100644 --- a/lib/layouts.js +++ b/lib/layouts.js @@ -145,7 +145,7 @@ function messagePassThroughLayout (loggingEvent) { */ function patternLayout (pattern, tokens) { 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; @@ -212,8 +212,25 @@ function patternLayout (pattern, tokens) { return '%'; } - function pid() { - return process.pid; + function pid(loggingEvent) { + 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) { @@ -237,6 +254,7 @@ function patternLayout (pattern, tokens) { 'r': startTime, '[': startColour, ']': endColour, + 'y': clusterInfo, 'z': pid, '%': percent, 'x': userDefined