Created
March 21, 2019 23:00
-
-
Save codeodor/8edfb7e1a2512e081824df6e688189df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DatabaseLogSubscriber < ActiveSupport::LogSubscriber | |
IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"] | |
def sql(event) | |
return unless logger.debug? | |
payload = event.payload | |
return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) | |
conn_id = payload[:connection_id] | |
conn = ObjectSpace._id2ref(conn_id) | |
from_connection = conn.active? ? conn.current_database : "No active connection" | |
name = "#{payload[:name]} (#{event.duration.round(1)}ms) #{from_connection}" | |
name = "CACHE #{name}" if payload[:cached] | |
name = color(name, RED) | |
debug " #{name}" | |
end | |
end | |
DatabaseLogSubscriber.attach_to :active_record |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment