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

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

问题描述

我想将一些 SQL 查询 Rails 执行的日志文件保存到日志文件中,(即 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 执行方法.您可以在那里添加任何日志逻辑.

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天全站免登陆