admin管理员组文章数量:1306822
I'm using npm package sequelize
+ mysql
and then:
let option = {logging: false}
While initializing:
new Sequelize(option)
It works fine for not outputting the query string.
However, it is still outputting the status code after I INSERT
or UPDATE
the database, and the result look like this: [ undefined, 1 ]
, [3 , 1]
(3 is the id, [AffectedID, AffectedRow]
)
I believe I need to change the cursor
settings, but I found none.
I'm following the instructions, so the code is basically very similar to : .html
I'm using the RAW query and here is my query sentence:
.query(query, {
replacements: parameters,
type: Sequelize.QueryTypes[qt]
})
So how can I stop this ? Should I change mysql settings directly or there is a better way ?
EDIT:
I just found out I had a auto-logger and I need to set it to false for insert and update, so thanks for the reply.
I'm using npm package sequelize
+ mysql
and then:
let option = {logging: false}
While initializing:
new Sequelize(option)
It works fine for not outputting the query string.
However, it is still outputting the status code after I INSERT
or UPDATE
the database, and the result look like this: [ undefined, 1 ]
, [3 , 1]
(3 is the id, [AffectedID, AffectedRow]
)
I believe I need to change the cursor
settings, but I found none.
I'm following the instructions, so the code is basically very similar to : http://docs.sequelizejs./manual/usage.html
I'm using the RAW query and here is my query sentence:
.query(query, {
replacements: parameters,
type: Sequelize.QueryTypes[qt]
})
So how can I stop this ? Should I change mysql settings directly or there is a better way ?
EDIT:
I just found out I had a auto-logger and I need to set it to false for insert and update, so thanks for the reply.
Share Improve this question edited Apr 30, 2019 at 7:21 asked Apr 26, 2019 at 20:15 user8379578user8379578 1- That doesn't seem like logging but something else. Can you show some code that generates that output? – tadman Commented Apr 26, 2019 at 20:17
4 Answers
Reset to default 4Instantiating sequelize takes in more parameters than just the options object. You need to also pass your database
, username
, and password
before your config options.
const sequelize = new Sequelize('database', 'username', 'password', {
logging: false
// rest of your config
});
There another way to stop logging of sequelize query. just add extra key named "logging": false,
of your sequelize config file.
here is example
{
"development": {
"username": "xxx",
"password": "",
"database": "xxx",
"host": "127.0.0.1",
"dialect": "mysql",
"operatorsAliases": false,
"timezone" : "+06:00"
},
"test": {
"username": "xxx",
"password": "xxx,
"database": "xxxx",
"host": "127.0.0.1",
"dialect": "mysql",
"timezone" : "+06:00"
},
"production": {
"logging": false,
"username": "xxxx",
"password": "xxx",
"database": "xxx",
"host": "127.0.0.1",
"dialect": "mysql",
"timezone" : "+06:00"
}
}
Its highly suggested to you to configure logging status from here, by this you can control your logging. cause production database should not showing log but production and test database should to showing log.
Besides @Trevor's answer is a good answer, Changing the logging on runtime cannot be achieved via his answer.
His answer turned off the logging whenever Sequelize
instance is created. But what about changing the logging on runtime. Say i want to turn off logging in few cases. To achieve that
const sequelize = new Sequelize('database', 'username', 'password', {
logging: false
// rest of your config
});
// your logging is turned off
// Somewhere else you
sequelize.options.logging = true
// Somewhere else you want logging to be turned off again
sequelize.options.logging = true
Reference From the source.
This behavior is quiet useful while development and run test on your code base. In development you want to see all logs, but in automated testing environment you are mainly interested in test results.
if you need to disable logging for a specific query:
const userProfileByCredentials = await Models.users.findOne({where: {email, password}, logging: false});
本文标签: javascriptHow to stop Node sequelize logging statusStack Overflow
版权声明:本文标题:javascript - How to stop Node sequelize logging status - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741777144a2397094.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论