From b694fd1d8d00518f4d6484957a7ccf43b8a1200c Mon Sep 17 00:00:00 2001 From: Christophe Bol Date: Mon, 1 Dec 2014 12:29:45 +0100 Subject: [PATCH 1/2] added cluster identifier support --- lib/appenders/clustered.js | 9 +++++++++ lib/layouts.js | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) 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 From 3300dfae600bf2c7bdc690dd974ce0f413b38128 Mon Sep 17 00:00:00 2001 From: Christophe Bol Date: Mon, 1 Dec 2014 15:34:09 +0100 Subject: [PATCH 2/2] fixed error when logging from the clustered master --- lib/layouts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/layouts.js b/lib/layouts.js index be5681c..1a1f094 100644 --- a/lib/layouts.js +++ b/lib/layouts.js @@ -213,7 +213,7 @@ function patternLayout (pattern, tokens) { } function pid(loggingEvent) { - if (loggingEvent.pid) { + if (loggingEvent && loggingEvent.pid) { return loggingEvent.pid; } else { return process.pid;