-
Notifications
You must be signed in to change notification settings - Fork 16
/
express-winston.node.txt
117 lines (95 loc) · 7.13 KB
/
express-winston.node.txt
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
EXPRESS-WINSTON
ALTERNATIVES ==> # - express-winston:
# - based on Express
# - logs REQ|RES.* as object with Winston
# - specify log level
# - can filter REQ|RES.*
# - can skip requests
# - error logging
# - morgan:
# - based on Express
# - logs REQ|RES.* as string to stdout
# - can skip requests
VERSION ==> #4.2.0
/=+===============================+=\
/ : : \
)==: REQUEST LOGGING :==(
\ :_______________________________: /
\=+===============================+=/
logger(OPTS)->MDWR #Express MDWR that does request logging.
#Fires WINSTON at request end (by monkey patching RES.end())
#Fires LOGGER.log({ level, message, meta })
OPTS.winstonInstance #LOGGER
OPTS.transports
OPTS.format #Create LOGGER using WINSTON.createLogger({ transports, format })
OPTS.level #LOGINFO.level STR[(REQ, RES)] (def: 'info')
OPTS.statusLevels #Alternative way to specify LOGINFO.level
#BOOL (def: false) or OBJ:
# - success STR (def: 'info'): for 1|2|3**
# - warn STR (def: 'warn'): for 4**
# - error STR (def: 'error'): for 5**
OPTS.skip(REQ, RES, ERROR)
->BOOL #
OPTS.msg #LOGINFO.message STR[(REQ, RES)]
#Can contain Mustach-like (actually using Lodash template) placeholders
# - template data is {{req|res.*}}
#Def: 'HTTP {{req.method}} {{req.url}}'
OPTS.expressFormat #If true (def: false), use '{{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms' instead
OPTS.colorize #If true (def: false), '{{res.statusCode}}' placeholder is colorized
# - green for 1**|2**, cyan for 3**, yellow for 4**, red for 5** (using CHALK, see its doc)
LOGINFO.meta #Merge of (from highest to lowest priority):
# - OPTS.baseMeta OBJ
# - OPTS.dynamicMeta(REQ, RES)->OBJ
# - LOGINFO.meta.req|res|responseTime
OPTS.meta #If false (def: true), do not use OPTS.dynamicMeta|LOGINFO.meta.*
LOGINFO.meta.req|res #REQ|RES
#res.body is JSON parsed if Content-Type: *json* [S]
LOGINFO.meta.responseTime #NUM. Uses RES.responseTime, which is set
#Difference from MDWR called and RES.end()
#Uses new Date()
OPTS|LOGINFO.metaField #'VARR' (def: 'meta'). Move LOGINFO.meta.* to LOGINFO.meta.PROP.*
#Can be null to move to LOGINFO.meta.*
OPTS|LOGINFO.requestField #'VARR'. Move LOGINFO.meta.req.* to LOGINFO.meta.PROP.*
OPTS.requestWhitelist #Only select 'VARR'_ARR from LOGINFO.meta.req.*
REQ._routeWhitelists.req #Def: ['url', 'headers', 'method', 'httpVersion', 'originalUrl', 'query']
#If both specified, do union
OPTS.requestFilter #Transform LOGINFO.meta.req.*
(REQ, 'PROP')->REQ.PROP #Done after whitelisting
OPTS.allowFilterOut
WhitelistedRequestBody #BOOL (def: false)
OPTS|LOGINFO.responseField
OPTS.responseWhitelist
REQ._routeWhitelists.res
OPTS.responseFilter #Same for LOGINFO.meta.res.*
(RES, 'PROP')->RES.PROP #Def: ['statusCode']
OPTS.bodyWhitelist #Same for LOGINFO.meta.req.body (must be whitelisted by LOGINFO.meta.res.* first)
REQ._routeWhitelists.body #If empty array (def), no filtering
#Uses OPTS.requestFilter too
OPTS.bodyBlacklist #'PROP'_ARR
OPTS.headersBlacklist #'HEADER'_ARR. Same for LOGINFO.meta.req.headers
OPTS.ignoreRoute|skip #If false, do not log that request
(REQ, RES)->BOOL #ignoreRoute() is fired when MDWR is called, skip() on request end
OPTS.ignoredRoutes #'URL'_ARR. If REQ.originalUrl|url among them, do not log that request
/=+===============================+=\
/ : : \
)==: ERROR LOGGING :==(
\ :_______________________________: /
\=+===============================+=/
errorLogger(OPTS)->MDWR #Like EXPRESS-WINSTON.logger() except is an error MDWR(ERROR, REQ, RES, NEXT)
# - log right away, i.e. no RES.end() monkey-patching
#Pass ERROR to:
# - OPTS.level[(REQ, RES, ERROR)] (def: 'error')
# - OPTS.msg template data req|res|err.*
# - OPTS.dynamicMeta(REQ, REQ, ERROR)->OBJ
#LOGINFO.meta.* is ERROR.* instead:
# - meta.req: same as above, without meta.req.body filtering
# - no meta.res
#Does not use:
# - OPTS.statusLevels|expressFormat|colorize|meta
# - REQ._routeWhitelists|Blacklists
# - responseTime
OPTS.exceptionToMeta(ERROR)
->LOGINFO.meta #Def: same LOGINFO as WINSTON's uncaught exception handler
OPTS.blacklistedMetaFields #'PROP'_ARR (def: [])