Amiga500
Amiga500

Reputation: 6131

Sails.js logging system

I need to implement logging to our sails server. I have found sails logging to file

But I am afraid I don't understand it very well. Intention is to replace console.log with log system.

This is just one example of many places where I need to implement logger:

  s3.putObject(params, function (err, data) {
                        if (err)
                            console.log(err);
                        else                         
                            console.log("Successfully uploaded " + 

//etc

Upvotes: 4

Views: 7443

Answers (3)

Syed Tabish Ali
Syed Tabish Ali

Reputation: 313

I have used sails.log("message"), sails.log.debug("message or variable"), sails.log.error("error message or variable").

Upvotes: 1

Abhi Patel
Abhi Patel

Reputation: 224

Just put this in your config/log.js

var winston = require('winston');
var customLogger = new winston.createLogger();

// A console transport logging debug and above.
customLogger.add(new winston.transports.Console, {
  level: 'debug',
  colorize: true
});

// A file based transport logging only errors formatted as json.
customLogger.add(new winston.transports.File({
  level: 'error',
  filename: './error.log',
  json: true,
  colorize: 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
};

now whenever you call sails.log.error() it will list your log in error.log file

sails.log.error("Error demo message");

Upvotes: 2

Diego Pamio
Diego Pamio

Reputation: 1358

You can use sails.log.error(), sails.log.warn(), sails.log.verbose(), etc to send logs to the console, or even to a file if you configure so in the config/logs.js file. There you can also specify the level of log to get in the output, or you can do it passing parameters in the sails command line (--verbose).

Upvotes: 4

Related Questions