Edit Page

sails.log()

Log a message or some data at the "debug" log level using Sails' built-in logger.

sails.log(...);

Usage

#

This function's usage is purposely 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.

Note that standard console.log() conventions from Node.js apply:

Example

#
var sum = +req.param('x') + +req.param('y');
sails.log();
sails.log('Hey %s, did you know that the sum of %d and %d is %d?', req.param('name'), +req.param('x'), +req.param('y'), sum);
sails.log('Bet you didn\'t know robots could do math, huh?');
sails.log();
sails.log('Anyways, here is a dictionary containing all the parameters I received in this request:', req.allParams());
sails.log('Until next time!');
return res.ok();

Notes

#
  • For a deeper conceptual exploration of logging in Sails, see concepts/logging.
  • Remember that, in addition to being exposed as an alternative to calling console.log directly, the built-in logger in Sails is called internally by the framework. The Sails logger can be configured, or completely overridden, using built-in log configuration settings (sails.config.log).
  • Keep in mind that, like any part of Sails, sails.log is completely optional. Most—but not all—Sails apps take advantage of the built-in logger: some users prefer to stick with console.log(), while others require() more feature-rich libraries like Winston. If you aren't sure what your app needs yet, start with the built-in logger and go from there.

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.

Reference

Reference