将每个SQL查询记录到Rails中的数据库 [英] Log every SQL query to database in Rails

查看:65
本文介绍了将每个SQL查询记录到Rails中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一些SQL查询轨道执行的操作保存到日志文件中(即CREATE,UPDATE和DELETE) 因此,我需要拦截所有查询,然后用一些正则表达式过滤它们,并根据需要记录它们.

I want to save to a log file some SQL query rails performs, (namely the CREATE, UPDATE and DELETE ones) therefore I need to intercept all queries and then filter them maybe with some regexp and log them as needed.

我会将这样的东西放在rails代码中的什么地方?

Where would I put such a thing in the rails code?

推荐答案

在Rails中进行SQL登录- 简而言之-您需要重写ActiveRecord execute方法.在那里,您可以添加任何用于记录的逻辑.

SQL logging in rails - In brief - you need to override ActiveRecord execute method. There you can add any logic for logging.

这篇关于将每个SQL查询记录到Rails中的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆