Way to disable Rails SQL logs?

后端 未结 3 747
清歌不尽
清歌不尽 2021-02-09 15:15

Is there a way to disable SQL logs in Rails, other than changing the log level? I\'ve got some logger.debug statements that I\'d like to print out in my ActiveRecord models, but

3条回答
  •  无人及你
    2021-02-09 16:12

    Here's what worked for me in Rails 3.0.5:

      class ActiveRecord::ConnectionAdapters::AbstractAdapter
        def log(sql, name)
          name ||= "SQL"
          yield
        rescue Exception => e
          message = "#{e.class.name}: #{e.message}: #{sql}"
          @logger.debug message if @logger
          raise translate_exception(e, message)
        end
      end
    

    It's this method with the line that writes to the log removed. SQL cache hits are still displayed in the log and I haven't figured out how to disable those.

提交回复
热议问题