6
6
* @license MIT
7
7
*/
8
8
9
+ // IDEA: request counts
10
+ // IDEA: unique function identifier
11
+
9
12
const UTILS = require ( './utils' ) // Require utils library
10
13
11
14
// Config logger
@@ -54,7 +57,6 @@ exports.config = (config,levels) => {
54
57
path : req . path ,
55
58
ip : req . ip ,
56
59
ua : req . userAgent ,
57
- method : req . method ,
58
60
version : req . version ,
59
61
qs : Object . keys ( req . query ) . length > 0 ? req . query : undefined
60
62
}
@@ -77,14 +79,15 @@ exports.config = (config,levels) => {
77
79
req : cfg . serializers && typeof cfg . serializers . req === 'function' ? cfg . serializers . req : ( ) => { } ,
78
80
res : cfg . serializers && typeof cfg . serializers . res === 'function' ? cfg . serializers . res : ( ) => { } ,
79
81
context : cfg . serializers && typeof cfg . serializers . context === 'function' ? cfg . serializers . context : ( ) => { } ,
80
- custom : cfg . serializers && typeof cfg . serializers . context === 'function' ? cfg . serializers . context : ( ) => { }
82
+ custom : cfg . serializers && typeof cfg . serializers . custom === 'function' ? cfg . serializers . custom : ( ) => { }
81
83
}
82
84
83
85
// Main logging function
84
86
let log = ( level , msg , req , context , custom ) => {
85
87
86
- let _context = Object . assign ( defaults . context ( context ) , serializers . custom ( context ) )
87
- let _custom = Object . assign ( defaults . custom ( custom ) , serializers . custom ( custom ) )
88
+ let _context = Object . assign ( { } , defaults . context ( context ) , serializers . context ( context ) )
89
+ let _custom = typeof custom === 'string' ? defaults . custom ( custom ) :
90
+ Object . assign ( { } , defaults . custom ( custom ) , serializers . custom ( custom ) )
88
91
89
92
return Object . assign ( { } ,
90
93
{
@@ -101,13 +104,14 @@ exports.config = (config,levels) => {
101
104
nested ? { [ customKey ] : _custom } : _custom ,
102
105
nested ? { context : _context } : _context
103
106
)
104
- }
107
+
108
+ } // end log
105
109
106
110
// Formatting function for additional log data enrichment
107
111
let format = function ( info , req , res ) {
108
112
109
- let _req = Object . assign ( defaults . req ( req ) , serializers . req ( req ) )
110
- let _res = Object . assign ( defaults . res ( res ) , serializers . res ( res ) )
113
+ let _req = Object . assign ( { } , defaults . req ( req ) , serializers . req ( req ) )
114
+ let _res = Object . assign ( { } , defaults . res ( res ) , serializers . res ( res ) )
111
115
112
116
return Object . assign ( { } ,
113
117
info ,
0 commit comments