MCPcopy Index your code
hub / github.com/restify/node-restify / audit

Function audit

lib/plugins/audit.js:266–322  ·  view source on GitHub ↗
(req, res, route, err)

Source from the content-addressed store, hash-verified

264 var serializers = Object.assign({}, DEFAULT_SERIALIZERS, opts.serializers);
265
266 function audit(req, res, route, err) {
267 var latency = res.get('Response-Time');
268
269 if (typeof latency !== 'number') {
270 latency = hrTimeDurationInMs(req._timeStart, req._timeFlushed);
271 }
272
273 var obj = {
274 remoteAddress: req.connection.remoteAddress,
275 remotePort: req.connection.remotePort,
276 [requestIdFieldName]: req.getId(),
277 req: req,
278 res: res,
279 err: err,
280 latency: latency,
281 secure: req.secure,
282 _audit: true,
283 event: opts.event
284 };
285
286 // run through the custom context function
287 if (opts.context) {
288 obj.context = opts.context(req, res, route, err);
289 }
290
291 const origLog = (req && req.log) || opts.log;
292 if (printLog && origLog) {
293 const log = origLog.child(
294 {
295 audit: true,
296 component: opts.event
297 },
298 {
299 serializers: serializers
300 }
301 );
302 switch (opts.event) {
303 case 'after':
304 log.info(obj, 'handled: %d', res.statusCode);
305 break;
306 case 'pre':
307 log.info(obj, 'pre');
308 break;
309 case 'routed':
310 log.info(obj, 'routed');
311 break;
312 default:
313 throw new Error('Unexpected audit event: ' + opts.event);
314 }
315 }
316
317 if (server) {
318 server.emit('audit', obj);
319 }
320
321 return true;
322 }
323

Callers

nothing calls this directly

Calls 1

hrTimeDurationInMsFunction · 0.85

Tested by

no test coverage detected