Skip to content

Cookbook: Configure Logging

David Souther edited this page Jan 15, 2015 · 4 revisions

Change log level

Rupert's logger has 9 levels. From most to least promiscuous, they are 'silly', 'data', 'debug', 'verbose', 'http', 'info', 'warn', 'error', and 'silent'. Default is 'http'.

For the Project

In the Rupert config object, the log object has a property, level. It should be a string, matching one of the above.

For the Run

To change the log level for a single run, set the environment variable LOG_LEVEL to a string value of one of the above.

Change HTTP Log Format

Rupert logs http requests at the 'http' level using morgan. Change the output format using log.level in the Rupert config object, or for a single run with the LOG_FORMAT environment variable. Default value is 'tiny', and valid are any morgan formats. At this time, it is not possible to define new morgan tokens for Rupert.

Using debug

The Rupert logger is an excellent tool to capture information necessary for devops and ongoing performance and analytics. The Rupert logger is less suitable to capturing short-term debugging information. Instead, use the debug utility.

var debug = require('debug')('myapp');
var error = require('debug')('myapp:ERROR');

function MyDataManager(options){
  debug('Loading data', options);
  if (!options.expectedRequiredParam){
    error('Options did not have expected parameter');
  }
}

To see the specific logs, set the DEBUG variable in the environment. DEBUG=myapp* npm start will run the Rupert application, and include any debugging information matching the myapp key.

Included debug levels

Rupert and many of its libraries use debug to provide additional information in development situations.

rupert*

Includes some rupert specific information, including loaded configuration settings.

stassets*

Includes detailed information on when files are modified, compiled, and ready to serve.

express*

Includes information on middleware and routes supplied to express.

socket.io

A tremendous wealth of information on when socket.io connections are created, used, and destroyed.