cf-nodejs-logging-support
Advanced tools
Comparing version 3.0.13 to 3.0.14
@@ -210,3 +210,3 @@ var util = require('util'); | ||
for (var key in fallbacks) { | ||
obj[key] = fallbacks[key](req, res, obj); | ||
obj[key] = fallbacks[key](obj); | ||
} | ||
@@ -256,7 +256,3 @@ | ||
// Writes the given log file to stdout | ||
var sendLog = function (level, logObject, dynamicLogLevel) { | ||
//Attach level to logobject | ||
logObject.level = level; | ||
var checkLoggingLevel = function(level, dynamicLogLevel) { | ||
var threshold; | ||
@@ -268,8 +264,9 @@ | ||
threshold = logLevelInt; // use global log level | ||
} | ||
} | ||
return (threshold >= loggingLevels[level]); | ||
} | ||
// Write log to console | ||
if (threshold >= loggingLevels[level]) { | ||
writeLogToConsole(logObject); | ||
} | ||
// Writes the given log file to stdout | ||
var sendLog = function (logObject) { | ||
writeLogToConsole(logObject); | ||
}; | ||
@@ -303,8 +300,7 @@ | ||
var level = args[0]; | ||
if (dynamicLogLevel != null) { // check if dynamic log level is setup | ||
if (dynamicLogLevel < loggingLevels[level]) { | ||
if (!checkLoggingLevel(level,this.dynamicLogLevel)) { | ||
return false; | ||
} | ||
} else if (logLevelInt < loggingLevels[level]) { | ||
return false; | ||
} else { | ||
var logObject = initLog(); | ||
logObject.level = level; | ||
} | ||
@@ -325,4 +321,2 @@ | ||
var logObject = initLog(); | ||
var req = this; | ||
@@ -351,3 +345,3 @@ if (req.logObject != null) { | ||
sendLog(level, logObject, dynamicLogLevel); | ||
sendLog(logObject); | ||
return true; | ||
@@ -410,3 +404,2 @@ }; | ||
return newContext; | ||
} | ||
@@ -477,2 +470,4 @@ | ||
exports.checkLoggingLevel = checkLoggingLevel; | ||
exports.init = init; | ||
@@ -479,0 +474,0 @@ exports.overrideField = overrideField; |
@@ -157,4 +157,4 @@ // Log network activity for express applications | ||
core.reduceFields(postConfig, logObject); | ||
core.sendLog('info', logObject, req.dynamicLogLevel); | ||
if(core.checkLoggingLevel(logObject.level,req.dynamicLogLevel)) | ||
core.sendLog(logObject); | ||
logSent = true; | ||
@@ -161,0 +161,0 @@ } |
@@ -146,3 +146,4 @@ // Log network activity for express applications | ||
core.sendLog('info', logObject, req.dynamicLogLevel); | ||
if(core.checkLoggingLevel(logObject.level,req.dynamicLogLevel)) | ||
core.sendLog(logObject); | ||
logSent = true; | ||
@@ -149,0 +150,0 @@ } |
@@ -149,3 +149,4 @@ /*jshint node:true */ | ||
core.sendLog('info', logObject, req.dynamicLogLevel); | ||
if(core.checkLoggingLevel(logObject.level,req.dynamicLogLevel)) | ||
core.sendLog(logObject); | ||
}); | ||
@@ -152,0 +153,0 @@ |
@@ -282,2 +282,9 @@ var uuid = require("uuid/v4"); | ||
} | ||
}, { | ||
name: "level", | ||
mandatory: true, | ||
source:{ | ||
type: "static", | ||
value: "info" | ||
} | ||
} | ||
@@ -284,0 +291,0 @@ ]; |
{ | ||
"name": "cf-nodejs-logging-support", | ||
"version": "3.0.13", | ||
"version": "3.0.14", | ||
"description": "Logging tool for Cloud Foundry", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -46,3 +46,3 @@ # Node.js Logging Support for Cloud Foundry | ||
// Context bound custom message | ||
req.logMessage("info", "Hello World will be send"); | ||
req.logMessage("info", "Hello World will be sent"); | ||
@@ -232,2 +232,28 @@ res.send('Hello World'); | ||
It is also possible to change the correlation_id: | ||
```js | ||
app.get('/', function (req, res) { | ||
// Call to context bound function | ||
req.setCorrelationId(YOUR_CUSTOM_CORRELATION_ID); | ||
res.send('Hello World'); | ||
}); | ||
``` | ||
### Correlation context objects | ||
As stated above the ```req``` acts as context preserving object and provides context bound functions like ```logMessage(...)```. In some cases you might want to create new context objects in order to create logs in context of other incoming data events (e.g. RabbitMQ). To do so you can use | ||
``` | ||
var ctx = log.getCorrelationObject(); | ||
ctx.logMessage(...); | ||
``` | ||
at any time to create new context objects. Custom context objects are provided with a newly generated correlation_id. | ||
Another usecase for this functionality is forwarding the context object of a request to other functions. Imagine a request handler that calls function ```foo()``` which should log messages in context of the original request. Instead of providing the ```req``` object to ```foo()``` it is a cleaner solution to create a new context object which retains the original correlation_id by calling: | ||
``` | ||
var ctx = req.getCorrelationObject(); | ||
foo(ctx); | ||
``` | ||
If you want to provide your own correlation_id, you can use the ```ctx.setCorrelationId(<id>)``` method. | ||
### Human readable output | ||
@@ -234,0 +260,0 @@ Setup an output pattern to get a human-readable output instead of json. Use '{{' and '}}' to print log parameters. |
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
86682
1312
275