Name: js-handler/node_modules/restify/lib/plugins/bunyan.js 
1:
// Copyright 2012 Mark Cavage, Inc.  All rights reserved.
2:
 
3:
var assert = require('assert-plus');
4:
 
5:
var shallowCopy = require('../utils').shallowCopy;
6:
 
7:
 
8:
 
9:
///--- API
10:
 
11:
function requestLogger(options) {
12:
        assert.optionalObject(options);
13:
        options = options || {};
14:
 
15:
        var props;
16:
        if (options.properties) {
17:
                props = shallowCopy(options.properties);
18:
        } else {
19:
                props = {};
20:
        }
21:
        if (options.serializers)
22:
                props.serializers = options.serializers;
23:
 
24:
        function bunyan(req, res, next) {
25:
                if (!req.log && !options.log) {
26:
                        next();
27:
                        return;
28:
                }
29:
 
30:
                var log = req.log || options.log;
31:
 
32:
                props.req_id = req.getId();
33:
                req.log = log.child(props, props.serializers ? false : true);
34:
                if (props.req_id)
35:
                        delete props.req_id;
36:
 
37:
                next();
38:
        }
39:
 
40:
        return (bunyan);
41:
}
42:
 
43:
 
44:
 
45:
///--- Exports
46:
 
47:
module.exports = requestLogger;