UGA Boxxx

つぶやきの延長のつもりで、知ったこと思ったこと書いてます

【Sequelize】ログの出力方法をかえる

以前、Sequelizeを使ってPostgresqlに接続する方法を調べた

uga-box.hatenablog.com

これを引き続き利用していたが、使用しているとログに実行したsqlが出力されていることに気付いたので止めたい

ドキュメントによるとインスタンスをつくるときのoption.loggingで設定できるみたい

sequelize.org

const sequelize = new Sequelize('sqlite::memory:', {
  // Choose one of the logging options
  logging: console.log,                  // Default, displays the first parameter of the log function call
  logging: (...msg) => console.log(msg), // Displays all log function call parameters
  logging: false,                        // Disables logging
  logging: msg => logger.debug(msg),     // Use custom logger (e.g. Winston or Bunyan), displays the first parameter
  logging: logger.debug.bind(logger)     // Alternative way to use custom logger, displays all messages
});

デフォルトはlogging: console.logになっているので、これをlogging: falseにすれば出力されなくなることがわかった