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
- MAX_QUERY_BYTES =
1024.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.
14 15 16 17 18 19 20 |
# File 'lib/timber/events/sql_query.rb', line 14 def initialize(attributes) @sql = attributes[:sql] || raise(ArgumentError.new(":sql is required")) @sql = @sql.byteslice(0, MAX_QUERY_BYTES) @time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required")) @time_ms = @time_ms.round(6) @message = attributes[:message] || raise(ArgumentError.new(":message is required")) end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
12 13 14 |
# File 'lib/timber/events/sql_query.rb', line 12 def @message end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
12 13 14 |
# File 'lib/timber/events/sql_query.rb', line 12 def sql @sql end |
#time_ms ⇒ Object (readonly)
Returns the value of attribute time_ms.
12 13 14 |
# File 'lib/timber/events/sql_query.rb', line 12 def time_ms @time_ms end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
28 29 30 |
# File 'lib/timber/events/sql_query.rb', line 28 def as_json( = {}) {:sql_query => to_hash} end |
#to_hash ⇒ Object Also known as: to_h
22 23 24 |
# File 'lib/timber/events/sql_query.rb', line 22 def to_hash {sql: sql, time_ms: time_ms} end |