在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);
}
}
我需要审核,所以如果这是创建审核日志的错误方法,我会对替代建议感兴趣。
答案 0 :(得分:0)
使用正则表达式对我来说似乎更简单。 对于你的情况
logFile.write(operation.replace(/Executing \([^\)]*\):\s*/, ''));