简体   繁体   English

Ruby on Rails SQL记录

[英]Ruby on Rails SQL Logging

Is it possible in Ruby on Rails to log only the SQL commands generated and save it on a separate file? Ruby on Rails中是否可以仅记录生成的SQL命令并将其保存在单独的文件中?

I'm still in development mode and looking to save all the SQL commands on a seperate log. 我仍处于开发模式,希望将所有SQL命令保存在单独的日志中。

I've checked the development.log files but they also save data like the 我已经检查了development.log文件,但它们也保存了诸如

"Started GET "/assets/application.css" for 127.0.0.1 at 2014-02-17 16:41:47 +0800, etc.

I am looking to either create a separate log file only for SQL or remove these other lines leaving only the SQL commands. 我正在寻找只为SQL创建一个单独的日志文件,或者删除其他仅保留SQL命令的其他行。

Is this possible? 这可能吗? Thank you. 谢谢。

如果您使用活动记录,则可以覆盖活动记录记录器:

ActiveRecord::Base.logger = Logger.new("#{Rails.root}/log/sql_log.log")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM