Class: Fluent::Debuggable

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_debug.rb

Overview

WOW! WHAT A FUCKING META PROGRAMMING!

Class Method Summary collapse

Class Method Details

.extend_configure(klass) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fluent/plugin/in_debug.rb', line 42

def self.extend_configure(klass)
  unless klass.method_defined?(:configure_without_debug)
    klass.config_param :debug, :bool, :default => false
    klass.__send__(:alias_method, :configure_without_debug, :configure)
    klass.__send__(:define_method, :configure_with_debug) do |conf|
      configure_without_debug(conf)
      Debuggable.extend_emit(self) if conf['debug']
    end
    klass.__send__(:alias_method, :configure, :configure_with_debug)
  end
end

.extend_emit(obj) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/in_debug.rb', line 28

def self.extend_emit(obj)
  klass = obj.singleton_class
  unless klass.method_defined?(:emit_without_debug)
    klass.__send__(:alias_method, :emit_without_debug, :emit)
    klass.__send__(:define_method, :emit_with_debug) do |tag, es, chain|
      es.each do |time, record|
        $log.write "#{Time.at(time).localtime} #{tag}: #{Yajl.dump(record)}\n"
      end
      emit_without_debug(tag, es, chain)
    end 
    klass.__send__(:alias_method, :emit, :emit_with_debug)
  end
end