I want to use the built in Sails.js logger and log everything to a file. The "filePath" variable used to work in 0.9.x in config/log.js, but it no longer appears to work in 0.10.x. Has this feature been removed - if so, what's the best way to log to disk now?
For logging, Sails.js (>= 0.10.0) relies on captains-log, a "lightweight logger with a simple pass-through configuration for use with fancier logging libraries."
To log to a file, you need to configure a custom logger. I would suggest you use Winston, and configure it with the File Transport. This is relatively easy to do:
$ npm install winston --save
var winston = require('winston');
var customLogger = new winston.Logger({
transports: [
new(winston.transports.File)({
level: 'debug',
filename: './logs/my_log_file.log'
}),
],
});
module.exports.log = {
colors: false, // To get clean logs without prefixes or color codings
custom: customLogger
};
sails.log.debug("Message to be logged");
$ sails lift
You should see content getting stored in your ./logs/my_log_file.log file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With