No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Express Request Logger

Logs express pending, slow, error and completed requests to redis. The redis server is fixed at the Metrological redis test server for easy inclusion into Metrological projects. Notice that logging is only performed when NODE_ENV is either production or test. In case of NODE_ENV dev or backendDev, logs are written to redis at localhost:6379.


  1. Add the logger to the express application, preferably before any other middleware:
	{projectName: "provisioningBackend"}

// Express config..
app.get('/', handleGet);

This will log all pending, slow and completed requests, but will not detect errors. Error requests will be logged as completed requests.

  1. To log error requests separately, set the .error property explicitly in the express response:
function errorResponse(request, response, message, debug) {
    if (response.rLog) { = {message: message, debug: debug};

    // Express stuff.
    config.getLogger().error('error', message, JSON.stringify(request.query), debug);
    response.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
  1. To attach extra meta-information to the log record:
if (res.rLog) {
	// Write additional meta info to log.
	if (req.user && { = {id:, name: req.user.username};
  1. To ignore some request:
app.use(function(req, res, next) {
	if (res.rLog) {
		if (req.path == '/') {
			// Ignore nagios calls.

Notice that if the request has already been logged at the moment of calling .ignore, the key is not deleted from redis. Preferably call ignore as soon as possible, for example in middleware appended directly after the request logger itself.