我有一个函数来检索用户的配置文件。
app.get('/api/user/profile', function (request, response)
{
// Create the default error container
var error = new Error();
var User = db.User;
User.find({
where: { emailAddress: request.user.username}
}).then(function(user)
{
if(!user)
{
error.status = 500; error.message = "ERROR_INVALID_USER"; error.code = 301;
return next(error);
}
// Build the profile from the user object
profile = {
"firstName": user.firstName,
"lastName": user.lastName,
"emailAddress": user.emailAddress
}
response.status(200).send(profile);
});
});
当"find“函数被调用时,它在启动服务器的控制台上显示select语句。
Executing (default): SELECT `id`, `firstName`, `lastName`, `emailAddress`, `password`, `passwordRecoveryToken`, `passwordRecoveryTokenExpire`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`emailAddress` = 'johndoe@doe.com' LIMIT 1;
有没有办法让它不被显示?我在某个配置文件中设置的某个标志?
发布于 2015-03-08 23:05:09
创建Sequelize对象时,将false
传递给logging
参数:
var sequelize = new Sequelize('database', 'username', 'password', {
// disable logging; default: console.log
logging: false
});
有关更多选项,请查看docs。
发布于 2016-08-26 15:27:49
如果使用了'config/ config.json‘文件,则将'logging':false添加到config.json中,在本例中位于开发配置部分。
// file config/config.json
{
{
"development": {
"username": "username",
"password": "password",
"database": "db_name",
"host": "127.0.0.1",
"dialect": "mysql",
"logging": false
},
"test": {
...
}
发布于 2017-05-09 23:50:29
就像在其他答案中一样,你可以只设置logging:false
,但我认为比起完全禁用日志记录,你可以在你的应用程序中接受日志级别。有时,您可能希望查看已执行的查询,因此将Sequelize配置为详细或调试级别的日志可能更好。例如(我在这里使用winston作为日志记录框架,但您可以使用任何其他框架):
var sequelize = new Sequelize('database', 'username', 'password', {
logging: winston.debug
});
仅当winston日志级别设置为debug或更低调试级别时,才会输出SQL语句。如果日志级别是warn或info,则不会记录SQL
https://stackoverflow.com/questions/28927836
复制相似问题