sails.config.log
Configuration for the logger in your Sails app. These settings apply whenever you call functions like sails.log.debug()
or sails.log.error()
in your app code, as well as when Sails logs a message to the console automatically. The options here are conventionally specified in the config/log.js configuration file.
Property | Type | Default | Details |
---|---|---|---|
level | 'info' |
Set the level of detail to be shown in your app's log. | |
inspect | true |
Set to false to disable captain's log's handling of logging, logs will instead be passed to the configured custom logger. | |
custom | undefined |
Specify a reference to an instance of a custom logger (such as Winston). If provided, instead of logging directly to the console, the functions exposed by the custom logger will be called, and log messages from Sails will be passed through. For more information, see captains-log. |
It is sometimes useful to configure a custom logger, particularly for regulatory compliance and organizational requirements (e.g. if your company is using a particular logger in other apps). In the context of Sails, configuring a custom logger also allows you to intercept all log messages automatically created by the framework, which is handy for setting up email notifications about errors and warnings.
Don't feel like you have to use a custom logger if you want these sorts of notifications! In fact, there are usually more straightforward ways to implement features like automated Slack, SMS, or email notifications when errors occur. One approach is to customize your app's default server error response (
responses/serverError.js
). Another popular option is to use a product like Papertrail, or a monitoring service like AppDynamics or NewRelic.
Here's an example configuring Winston as a custom logger, defining both a console transport and file transport:
// config/log.js
var winston = require('winston');
var customLogger = new winston.Logger();
// A console transport logging debug and above.
customLogger.add(winston.transports.Console, {
level: 'debug',
colorize: true
});
// A file based transport logging only errors formatted as json.
customLogger.add(winston.transports.File, {
level: 'error',
filename: 'filename.log',
json: true
});
module.exports.log = {
// Pass in our custom logger, and pass all log levels through.
custom: customLogger,
level: 'silly',
// Disable captain's log so it doesn't prefix or stringify our meta data.
inspect: false
};