Module: Octopus::LogSubscriber

Defined in:
lib/octopus/log_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/octopus/log_subscriber.rb', line 4

def self.included(base)
  base.send(:attr_accessor, :octopus_shard)

  base.send :alias_method, :sql_without_octopus_shard, :sql
  base.send :alias_method, :sql, :sql_with_octopus_shard

  base.send :alias_method, :debug_without_octopus_shard, :debug
  base.send :alias_method, :debug, :debug_with_octopus_shard
end

Instance Method Details

#debug_with_octopus_shard(msg) ⇒ Object



19
20
21
22
# File 'lib/octopus/log_subscriber.rb', line 19

def debug_with_octopus_shard(msg)
  conn = octopus_shard ? color("[Shard: #{octopus_shard}]", ActiveSupport::LogSubscriber::GREEN, true) : ''
  debug_without_octopus_shard(conn + msg)
end

#sql_with_octopus_shard(event) ⇒ Object



14
15
16
17
# File 'lib/octopus/log_subscriber.rb', line 14

def sql_with_octopus_shard(event)
  self.octopus_shard = event.payload[:octopus_shard]
  sql_without_octopus_shard(event)
end