Class: TorqueBox::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Logger

Returns a new instance of Logger.



5
6
7
8
# File 'lib/torquebox/logger.rb', line 5

def initialize name = nil
  category = name || (TORQUEBOX_APP_NAME if defined? TORQUEBOX_APP_NAME) || "TorqueBox"
  @logger = org.jboss.logging::Logger.getLogger( category.to_s.gsub('::','.') )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/torquebox/logger.rb', line 16

def method_missing(method, *args, &block)
  delegate = method
  if method.to_s.end_with?('?')
    delegate = "#{method.to_s.chop}_enabled?".to_sym
  end
  self.class.class_eval do
    define_method(method) do |*a, &b|
      params = [ a[0] || (b && b.call) ].compact
      @logger.send(delegate, *params)
    end
  end
  self.send(method, *args, &block)
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



14
15
16
# File 'lib/torquebox/logger.rb', line 14

def level
  @level
end