cf-nodejs-logging-support
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -16,2 +16,3 @@ var util = require('util'); | ||
var fixedValues = {}; | ||
var initDummy = null; | ||
@@ -21,2 +22,3 @@ var logLevelInt = 2; | ||
var stdout = process.stdout; | ||
var patternDivider = /((?:\{\{)([^\}\{]+)(?:\}\}))/g; | ||
var uuidCheck = /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}/; | ||
@@ -30,10 +32,18 @@ | ||
if (undefined !== logObject && logObject != null) { | ||
output = pattern; | ||
for (var key in logObject) { | ||
if (typeof (logObject[key]) === "object" && validObject(logObject[key])) { | ||
output = output.replace('{{' + key + '}}', JSON.stringify(logObject[key])); | ||
} else { | ||
output = output.replace('{{' + key + '}}', logObject[key]); | ||
output = ""; | ||
var rest = pattern.split(patternDivider); | ||
var value; | ||
for (i = 0; i < (rest.length - 1) / 3; i++) { | ||
output += rest[i * 3]; | ||
value = logObject[rest[2 + i * 3]]; | ||
if (value != null) { | ||
if (typeof value == "string") { | ||
output += value; | ||
} else { | ||
output += JSON.stringify(value); | ||
} | ||
} | ||
} | ||
output += rest[rest.length - 1]; | ||
} | ||
@@ -49,3 +59,3 @@ } else { | ||
var setLoggingLevel = function (level) { | ||
if(loggingLevels[level] != undefined){ | ||
if (loggingLevels[level] != undefined) { | ||
logLevelInt = loggingLevels[level]; | ||
@@ -239,3 +249,24 @@ return true; | ||
var writeStaticFields = function (logObject) { | ||
for (var key in fixedValues) { | ||
logObject[key] = fixedValues[key]; | ||
} | ||
} | ||
// overrides Values in ALL Network logs (will impact log parsing, so use with caution!), returns true if field is set. | ||
var overrideField = function (field, value) { | ||
if (field != null && typeof field == "string") { | ||
if (value == undefined || value == null) { | ||
fixedValues[field] = null; | ||
return true; | ||
} else { | ||
fixedValues[field] = value; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
exports.overrideField = overrideField; | ||
exports.writeStaticFields = writeStaticFields; | ||
exports.setLoggingLevel = setLoggingLevel; | ||
@@ -242,0 +273,0 @@ exports.getLoggingLevel = getLoggingLevel; |
@@ -66,3 +66,2 @@ // Log network activity for express applications | ||
logObject.direction = "IN"; | ||
logObject.msg = ""; | ||
@@ -94,5 +93,3 @@ req.logObject = logObject; | ||
//override values with predefined values | ||
for(var key in fixedValues) { | ||
logObject[key] = fixedValues[key]; | ||
} | ||
core.writeStaticFields(logObject); | ||
core.sendLog('info', logObject); | ||
@@ -119,7 +116,8 @@ logSent = true; | ||
} | ||
// overrides Values in ALL Network logs (will impact log parsing, so use with caution!) | ||
var overrideField = function (field, value) { | ||
fixedValues[field] = value; | ||
return core.overrideField(field, value); | ||
} | ||
exports.overrideField = overrideField; | ||
exports.setCoreLogger = setCoreLogger; | ||
@@ -126,0 +124,0 @@ exports.setLoggingLevel = setLoggingLevel; |
@@ -56,3 +56,2 @@ // Log network activity for express applications | ||
logObject.direction = "IN"; | ||
logObject.msg = ""; | ||
@@ -82,5 +81,3 @@ req.logObject = logObject; | ||
//override values with predefined values | ||
for (var key in fixedValues) { | ||
logObject[key] = fixedValues[key]; | ||
} | ||
core.writeStaticFields(logObject); | ||
core.sendLog('info', logObject); | ||
@@ -97,2 +94,4 @@ logSent = true; | ||
var setLogPattern = function (pattern) { | ||
@@ -106,7 +105,8 @@ core.setLogPattern(pattern); | ||
} | ||
// overrides Values in ALL Network logs (will impact log parsing, so use with caution!) | ||
var overrideField = function (field, value) { | ||
fixedValues[field] = value; | ||
return core.overrideField(field, value); | ||
} | ||
exports.overrideField = overrideField; | ||
exports.setCoreLogger = setCoreLogger; | ||
@@ -113,0 +113,0 @@ exports.setLoggingLevel = setLoggingLevel; |
@@ -69,3 +69,2 @@ /*jshint node:true */ | ||
logObject.direction = "IN"; | ||
logObject.msg = ""; | ||
@@ -87,5 +86,3 @@ req.logObject = logObject; | ||
//override values with predefined values | ||
for(var key in fixedValues) { | ||
logObject[key] = fixedValues[key]; | ||
} | ||
core.writeStaticFields(logObject); | ||
core.sendLog('info', logObject); | ||
@@ -107,10 +104,11 @@ }); | ||
// Provides a context object, which allows message logging and uses correlationId from its parent request. | ||
var getCorrelationObject = function() { | ||
var getCorrelationObject = function () { | ||
return core.getCorrelationObject(); | ||
} | ||
// overrides Values in ALL Network logs (will impact log parsing, so use with caution!) | ||
var overrideField = function (field, value) { | ||
fixedValues[field] = value; | ||
return core.overrideField(field, value); | ||
} | ||
exports.overrideField = overrideField; | ||
exports.setCoreLogger = setCoreLogger; | ||
@@ -122,2 +120,2 @@ exports.setLoggingLevel = setLoggingLevel; | ||
exports.getCorrelationObject = getCorrelationObject; | ||
exports.overrideField = overrideField; | ||
exports.overrideField = overrideField; |
{ | ||
"name": "cf-nodejs-logging-support", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Logging tool for Cloud Foundry", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -11,3 +11,3 @@ # Node.js Logging Support for Cloud Foundry | ||
#### Version 2.0 introduced loging without Winston and changed custom fields to be parsed and reported as strings regardless of original type. | ||
#### Version 2.0 introduced logging without Winston and changed custom fields to be parsed and reported as strings regardless of original type. | ||
@@ -14,0 +14,0 @@ ## Features |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45262
620