Class: Dry::Monitor::SQL::Logger
- Inherits:
-
Object
- Object
- Dry::Monitor::SQL::Logger
- Extended by:
- Configurable, Core::Extensions
- Defined in:
- lib/dry/monitor/sql/logger.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(logger, config = self.class.config) ⇒ Logger
constructor
A new instance of Logger.
- #log_query(time:, name:, query:) ⇒ Object
- #subscribe(notifications) ⇒ Object
Constructor Details
#initialize(logger, config = self.class.config) ⇒ Logger
Returns a new instance of Logger.
45 46 47 48 49 |
# File 'lib/dry/monitor/sql/logger.rb', line 45 def initialize(logger, config = self.class.config) @logger = logger @config = config @template = config. end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
41 42 43 |
# File 'lib/dry/monitor/sql/logger.rb', line 41 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
41 42 43 |
# File 'lib/dry/monitor/sql/logger.rb', line 41 def logger @logger end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
41 42 43 |
# File 'lib/dry/monitor/sql/logger.rb', line 41 def template @template end |
Instance Method Details
#log_query(time:, name:, query:) ⇒ Object
55 56 57 |
# File 'lib/dry/monitor/sql/logger.rb', line 55 def log_query(time:, name:, query:) logger.info template % [name.inspect, time, colorizer.call(query)] end |
#subscribe(notifications) ⇒ Object
51 52 53 |
# File 'lib/dry/monitor/sql/logger.rb', line 51 def subscribe(notifications) notifications.subscribe(:sql) { |params| log_query(**params) } end |