在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);
}
}我的需求是审计,所以如果这是创建审计日志的错误方法,我会对替代建议感兴趣。
发布于 2017-03-10 20:04:23
在我看来,使用正则表达式要简单得多。对于你的案例
logFile.write(operation.replace(/Executing \([^\)]*\):\s*/, ''));
https://stackoverflow.com/questions/42124082
复制相似问题