-
Notifications
You must be signed in to change notification settings - Fork 1
/
logHttpRequest.js
40 lines (33 loc) · 1.04 KB
/
logHttpRequest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* logHttpRequest.js: Helper for logging http requests
*
* (C) 2012 Crosstalk Systems Inc.
*/
var stdjson = require( 'stdjson' )(),
util = require( 'util' );
//
// ### function logHttpRequest ( workerName, method, path, headers, body,
// options )
// #### @workerName {string} the name of the worker
// #### @request {object} http(s) request object
// #### @body {string|object} http request body
// #### @options {object} logging options
// Logs the http request to stdout.
//
var logHttpRequest = function logHttpRequest ( workerName, request, body,
options ) {
options = options || {};
request = request || {};
var protocol = options.protocol || "HTTP";
var notice = options.outbound ? "REQUESTING" : "HANDLING";
stdjson.log( notice + " " + protocol.toUpperCase(), {
workerName : workerName,
host : request.host,
method : request.method,
path : request.path,
url : request.url,
headers : request.headers,
body : body ? body.toString() : ""
});
}; // logHttpRequest
module.exports = logHttpRequest;