简体   繁体   English

SailsJS日志请求参数

[英]SailsJS Log Request Params

so my problem is that I want to log any request to my sails app. 所以我的问题是我想将任何请求记录到我的Sails应用程序中。 Basically I've got it working with the one problem that I can't log the params of the request. 基本上,我已经解决了一个无法记录请求参数的问题。

myRequestLogger: function(req, res, next) {
            if (sails.config.environment === 'development') {
                console.log('=========================================================');

                console.log("Request :: ", req.method, req.url, req.param);

                console.log('=========================================================');
            }

            return next();
        },

req.allParams() returns it isn't a function and req.param(...) returns undefined. req.allParams()返回它不是函数,而req.param(...)返回未定义。 Do I have to impement this in another position? 我是否必须在其他位置执行此操作? Does anybody knows what I'm doing wrong? 有人知道我在做什么错吗?

Bruno 布鲁诺

EDIT 编辑

I use the default order inside the http.js : 我在http.js中使用默认顺序:

order: [
            'startRequestTimer',
            'cookieParser',
            'session',
            'passportInit',
            'passportSession',
            'myRequestLogger',
            'bodyParser',
            'handleBodyParserError',
            'compress',
            'methodOverride',
            'poweredBy',
            '$custom',
            'router',
            'www',
            'favicon',
            '404',
            '500'
        ]

Found the answer ... The order has to be different. 找到了答案...顺序必须不同。 The requestLogger has to be implemented after the bodyParser: requestLogger必须在bodyParser之后实现:

order: [
            ...
            'bodyParser',
            'myRequestLogger',
            'handleBodyParserError',
            '...
        ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM