cf-nodejs-logging-support
Advanced tools
Comparing version 1.0.1 to 1.1.1
@@ -53,3 +53,2 @@ // Log network activity for express applications | ||
logObject.referer = "-"; | ||
logObject.response_sent_at = (new Date()).toJSON(); | ||
logObject.response_status = -1; // Set later | ||
@@ -87,3 +86,5 @@ logObject.method = req.method == null ? "-" : req.method; | ||
if (!logSent) { | ||
logObject.response_time_ms = Date.now() - start; | ||
var timeObj = new Date(); | ||
logObject.response_sent_at = timeObj.toJSON(); | ||
logObject.response_time_ms = timeObj.getTime() - start; | ||
logObject.response_size_b = res.get("content-length") == null ? -1 : res.get("content-length"); | ||
@@ -90,0 +91,0 @@ logObject.response_content_type = res.get("content-type") == null ? "-" : res.get("content-type"); |
@@ -55,3 +55,2 @@ /*jshint node:true */ | ||
logObject.referer = "-"; | ||
logObject.response_sent_at = (new Date()).toJSON(); | ||
logObject.response_status = 200; // Set later | ||
@@ -79,3 +78,5 @@ logObject.method = req.method == null ? "-" : req.method; | ||
res.on('finish', function () { | ||
logObject.response_time_ms = Date.now() - start; | ||
var timeObj = new Date(); | ||
logObject.response_sent_at = timeObj.toJSON(); | ||
logObject.response_time_ms = timeObj.getTime() - start; | ||
logObject.response_size_b = res.get("content-length") == null ? -1 : res.get("content-length"); | ||
@@ -82,0 +83,0 @@ logObject.response_content_type = res.get("content-type") == null ? "-" : res.get("content-type"); |
@@ -21,2 +21,5 @@ //loading core logger functionality | ||
break; | ||
case "plainhttp": | ||
effectiveLogger = require("./cf-nodejs-logging-support-plainhttp/log-plainhttp"); | ||
break; | ||
default: | ||
@@ -23,0 +26,0 @@ effectiveLogger = require("./cf-nodejs-logging-support-express/log-express"); |
{ | ||
"name": "cf-nodejs-logging-support", | ||
"version": "1.0.1", | ||
"version": "1.1.1", | ||
"description": "Logging tool for Cloud Foundry", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# Node.js Logging Support for Cloud Foundry | ||
[](https://www.npmjs.com/package/cf-nodejs-logging-support)[](https://www.npmjs.com/package/cf-nodejs-logging-support)[](https://travis-ci.org/SAP/cf-nodejs-logging-support) | ||
## Summary | ||
This is a collection of support libraries for node.js applications running on Cloud Foundry that serve two main purposes: It provides (a) means to emit *structured application log messages* and (b) instrument parts of your application stack to *collect request metrics*. | ||
For details on the concepts and log formats, please look at the sibling project for [java logging support](https://github.com/SAP/cf-java-logging-support). | ||
## Features | ||
@@ -43,2 +48,41 @@ | ||
``` | ||
### Other Server Libraries | ||
The logging library defaults to express middleware behaviour, but it can be forced to work with other Server libraries as well: | ||
#### With restify: | ||
``` | ||
var restify = require('restify'); | ||
var log = require('cf-nodejs-logging-support'); | ||
var app = restify.createServer(); | ||
//forces logger to run the restify version. (default is express, forcing express is also legal) | ||
log.forceLogger("restify"); | ||
//insert the logger in the server network queue, so each time a https request is recieved, it is will get logged. | ||
app.use(log.logNetwork); | ||
//same usage as express logger, see minimal example above | ||
``` | ||
#### With nodejs http: | ||
``` | ||
var log = require("cf-nodejs-logging-support"); | ||
const http = require('http'); | ||
//forces logger to run the http version. | ||
log.forceLogger("plainhttp"); | ||
const server = http.createServer((req, res) => { | ||
//binds logging to the given request for request tracking | ||
log.logNetwork(req, res); | ||
// Context bound custom message | ||
req.logMessage("info", "request bound information:", { | ||
"some": "info" | ||
}); | ||
res.end('ok'); | ||
}); | ||
server.listen(3000); | ||
// Formatted log message free of request context | ||
log.logMessage("info", "Server is listening on port %d", 3000); | ||
``` | ||
### Custom Messages | ||
@@ -45,0 +89,0 @@ |
38244
11
464
172