Class: Timber::Events::SQLQuery
- Inherits:
-
Timber::Event
- Object
- Timber::Event
- Timber::Events::SQLQuery
- Defined in:
- lib/timber/events/sql_query.rb
Overview
Note:
This event should be installed automatically through integrations, such as the Integrations::ActiveRecord::LogSubscriber integration.
The SQL query event tracks sql queries to your database.
Constant Summary collapse
- MESSAGE_MAX_BYTES =
8192.freeze
- SQL_MAX_BYTES =
4096.freeze
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
-
#time_ms ⇒ Object
readonly
Returns the value of attribute time_ms.
Instance Method Summary collapse
-
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
-
#initialize(attributes) ⇒ SQLQuery
constructor
A new instance of SQLQuery.
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(attributes) ⇒ SQLQuery
Returns a new instance of SQLQuery.
15 16 17 18 19 20 |
# File 'lib/timber/events/sql_query.rb', line 15 def initialize(attributes) normalizer = Util::AttributeNormalizer.new(attributes) @message = normalizer.fetch!(:message, :string, :limit => MESSAGE_MAX_BYTES) @sql = normalizer.fetch!(:sql, :string, :limit => SQL_MAX_BYTES) @time_ms = normalizer.fetch!(:time_ms, :float, :precision => 6) end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
13 14 15 |
# File 'lib/timber/events/sql_query.rb', line 13 def @message end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
13 14 15 |
# File 'lib/timber/events/sql_query.rb', line 13 def sql @sql end |
#time_ms ⇒ Object (readonly)
Returns the value of attribute time_ms.
13 14 15 |
# File 'lib/timber/events/sql_query.rb', line 13 def time_ms @time_ms end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
31 32 33 |
# File 'lib/timber/events/sql_query.rb', line 31 def as_json( = {}) {:sql_query => to_hash} end |
#to_hash ⇒ Object Also known as: to_h
22 23 24 25 26 27 |
# File 'lib/timber/events/sql_query.rb', line 22 def to_hash @to_hash ||= Util::NonNilHashBuilder.build do |h| h.add(:sql, sql) h.add(:time_ms, time_ms) end end |