Class: Dry::Monitor::SQL::Logger

Inherits:
Object
  • Object
show all
Extended by:
Configurable, Core::Extensions
Defined in:
lib/dry/monitor/sql/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.message_template
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



41
42
43
# File 'lib/dry/monitor/sql/logger.rb', line 41

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



41
42
43
# File 'lib/dry/monitor/sql/logger.rb', line 41

def logger
  @logger
end

#templateObject (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