DEV Community

Thomas Step
Thomas Step

Posted on • Edited on • Originally published at thomasstep.com

Using Bunyan with Sequelize

While trying to use Bunyan logger with Sequelize ORM, I ran across this issue on GitHub that I tried to use to solve my problem. It worked and the error that I was getting before was not there anymore; however, it was giving me extra information that I did not necessarily want. The information it gave me was about attributes and other options in Sequelize. I did not want to see that every time something was logged in Sequelize though. After some more digging, I learned that the logging option in Sequelize just takes a function that it passes a message into to be logged. I did a quick and dirty fix to this by creating a function with a message parameter and logging it with Bunyan. It looks like this:


const logger = (msg) => {
  log.info(msg);
};
...
  logging: logger
...

Enter fullscreen mode Exit fullscreen mode

The logging: logger part goes into your options object that's passed in during connection. I had not seen this solution anywhere, so I commented on the issue thread and thought I would share here as well.

Top comments (0)