Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Node sequelize logging status

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.com/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.


2 Answers

Instantiating 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
});
like image 185
Trevor Johnson Avatar answered Sep 23 '25 00:09

Trevor Johnson


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.

like image 35
Ratul Sharker Avatar answered Sep 23 '25 00:09

Ratul Sharker