How to Log in SailsJS

十年热恋 提交于 2020-01-01 04:08:08

问题


What is the actual syntax to log in SailsJS?

Docs don't have anything, but found the following line in the site's roadmap

"Pull out Sails.log (winston wrapper) as a separate module so it can be used by waterline"

I image it's something like:

Sails.log(...)
Sails.error(...)
Sails.warn(...)

回答1:


In your controllers, models, services, and anywhere else that the sails global is available, you can log with one of:

sails.log();
sails.log.warn();
sails.log.info();
sails.log.debug();
sails.log.error();
sails.log.verbose();
sails.log.silly();

The logging level (that is, the level at which logs will be output to the console) is set in /config/log.js.




回答2:


To extend on the Scott Answer, dont forget to add the filePath: property to log.js file... otherwise it will not work :)

So it should be something like:

log: {
level: 'info',
maxSize: 1000,
filePath: 'c://serverlogs/mylogfilename.log'

Answer is changed based on Joseph question.



来源:https://stackoverflow.com/questions/22591861/how-to-log-in-sailsjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!