Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sails logging to file

Tags:

Can someone provide an example of how to configure sails.js to log to a file?

It seems like it should be straightforward, but I'm having trouble finding examples online.

I'm looking at changes in the config/log.js or the config/sockets.js files.

like image 907
rcheuk Avatar asked Dec 09 '13 20:12

rcheuk


2 Answers

According to the source code, for v0.9.x, you just have to set the filePath in your config/log.js:

module.exports = {
  log: {
    level: 'info',
    filePath: 'application.log'
  }
};
like image 89
bredikhin Avatar answered Sep 21 '22 18:09

bredikhin


Logging to a file doesn't work out of the box. You need to invoke functionality in libraries two levels down. See the documentation for winston.

first install winston like so:

$ npm install winston

Then adjust config/log.js to look as follows

var winston = require('winston');

/*see the documentation for Winston:  https://github.com/flatiron/winston */
var logger = new(winston.Logger)({
  transports: [
    new (winston.transports.Console)({}),
    new (winston.transports.File)({
      filename: 'logfile.log',
      level: 'verbose',
      json: false,
      colorize: false
    })
  ]
});

module.exports.log = {
  /***************************************************************************
   *                                                                          *
   * Valid `level` configs: i.e. the minimum log level to capture with        *
   * sails.log.*()                                                            *
   *                                                                          *
   * The order of precedence for log levels from lowest to highest is:        *
   * silly, verbose, info, debug, warn, error                                 *
   *                                                                          *
   * You may also set the level to "silent" to suppress all logs.             *
   *                                                                          *
   ***************************************************************************/

  level: 'silly',
  colorize: false,
  custom: logger
};
like image 30
djsadinoff Avatar answered Sep 23 '22 18:09

djsadinoff