Edit Page

Logging

Sails comes with a simple, built-in logger called captains-log. Its usage is functionally very similar to Node's console.log, but with a handful of extra features, namely support for multiple log levels with colorized, prefixed console output. The logger serves two purposes:

Configuration

#

Sails' log configuration is determined by sails.config.log, which is conventionally set by a generated configuration file (config/log.js) in new Sails projects out of the box.

Usage

#
sails.log.info('I am an info-level message.');
sails.log('I am a debug-level message');
sails.log.warn('I am a warn-level message');

Log levels

#

Using the built-in logger, Sails will write output (to stdout/stderr) for log function calls that are _at_ or above the priority of the currently-configured log level. This log level is normalized and also applied to generated output from Grunt, Socket.io, Waterline, Express, and other dependencies. The hierarchy of log levels and their relative priorities is summarized by the chart below:

Priority Level Log fns that produce visible output
0 silent N/A
1 error .error()
2 warn .warn(), .error()
3 debug .debug(), .warn(), .error()
4 info .info(), .debug(), .warn(), .error()
5 verbose .verbose(), .info(), .debug(), .warn(), .error()
6 silly .silly(), .verbose(), .info(), .debug(), .warn(), .error()

Notes

#

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Concepts