I have a Sails.js project that I would like to add LogEntries support for event logging. However I would like to use LogEntries only in some environments.
For example, in development I don't want to fill the logs with development garbage.
// config/log.js
var logentries = require('le_node');
var log = (sails.config.environment === 'development') ? sails.log : logentries.logger({
token: 'YOUR_TOKEN'
});
module.exports.log = {
log: {
custom: log
}
}
But with this I get an error that the sails
is not defined. This is because sails
object is not available in configuration files such as config/log.js
. So how can use a custom log transport depending on the environment in this case?
In the end what seems correct was not modify the config/log.js
file directly but to modify the environment configuration file:
// config/env/production.js
var logentries = require('le_node');
var log = logentries.logger({
token: 'YOUR_TOKEN'
});
module.exports.log = {
log: {
custom: log
}
}
This way only the production environment will have the custom logging.