Prevent Sequelize from SQL output to console while query execution?

I have a function to get a user profile.

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); }); }); 

When the find function is called, it displays the select statement on the console on which the server was started.

 Executing (default): SELECT `id`, `firstName`, `lastName`, `emailAddress`, `password`, `passwordRecoveryToken`, `passwordRecoveryTokenExpire`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`emailAddress` = 'johndoe@doe.com' LIMIT 1; 

Is there any way to prevent this from showing up? Some flag that I set somewhere in the configuration file?

+147
Mar 08 '15 at 14:56
source share
3 answers

When you create a Sequelize object, pass false to the logging parameter:

 var sequelize = new Sequelize('database', 'username', 'password', { // disable logging; default: console.log logging: false }); 

Additional options: docs .

+267
Mar 08 '15 at 15:05
source share
β€” -

If the file 'config / config.json' is used, then add 'logging': false to config.json in this case, in the development configuration section.

  // file config/config.json { { "development": { "username": "username", "password": "password", "database": "db_name", "host": "127.0.0.1", "dialect": "mysql", "logging": false }, "test": { ... } 
+27
Aug 26 '16 at 7:27
source share

As with the other answers, you can just set logging:false , but I think it's better than completely disabling logging, you can just cover the log levels in your application. Sometimes you can take a look at the executed queries, so it’s better to configure Sequelize to register at verbose or debug level. for example (I use winston here as a logging structure, but you can use any other infrastructure):

 var sequelize = new Sequelize('database', 'username', 'password', { logging: winston.debug }); 

This will only result in SQL statements being output if the Winston log level is set to debug or lower debug levels. If the log level is a warning or information, for example, SQL will not be logged

+16
May 9, '17 at 15:50
source share



All Articles