【问题标题】:Logging just the SQL with Sequelize logging, for audit logging?仅使用 Sequelize 日志记录 SQL,用于审计日志记录?
【发布时间】:2017-06-26 17:13:46
【问题描述】:

在 Sequelize 中登录时是否可以只获取 SQL?我想记录所有修改的 SQL 语句,作为审计过程的一部分,但是对我的日志记录函数的调用会收到以下形式的文本:

 Executing (9dcde3e9-cd1c-4964-bf87-a29d75a8c76e): INSERT INTO `login_attempts` VALUES (1,'bob@example.com',1,'2016-11-30 18:20:26.540 +00:00');

在我的 Node.JS 中,我可以做一些事情,尽管我想知道是否有可能有一些更简单的东西,因为它会在对数据库的每个操作中被调用:

if (operation.startsWith('Executing') && operation.indexOf(':') > -1) {
   var str = operation.substring(operation.indexOf(':') + 2, operation.length);
   if (str.startsWith('INSERT') || str.startsWith('DELETE') || str.startsWith('UPDATE')) {
       logFile.write(str);
   }
}

我需要审计,所以如果这是创建审计日志的错误方法,我会对替代建议感兴趣。

【问题讨论】:

    标签: node.js sequelize.js


    【解决方案1】:

    对我来说,使用正则表达式似乎要简单得多。 适合你的情况

    logFile.write(operation.replace(/Executing \([^\)]*\):\s*/, ''));

    【讨论】:

      猜你喜欢
      • 2016-03-23
      • 2011-03-18
      • 2011-01-30
      • 1970-01-01
      • 2011-02-02
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多