Class: RootLogger::ClassLogger
- Inherits:
-
Object
- Object
- RootLogger::ClassLogger
- Defined in:
- lib/unicorn-cuba-base/root_logger.rb
Constant Summary collapse
- @@levels =
[:debug, :info, :warn, :error, :fatal, :unknown]
Instance Attribute Summary collapse
-
#root_logger ⇒ Object
readonly
Returns the value of attribute root_logger.
Instance Method Summary collapse
-
#initialize(root_logger, class_obj) ⇒ ClassLogger
constructor
A new instance of ClassLogger.
- #inspect ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to?(method) ⇒ Boolean
Constructor Details
#initialize(root_logger, class_obj) ⇒ ClassLogger
Returns a new instance of ClassLogger.
8 9 10 11 |
# File 'lib/unicorn-cuba-base/root_logger.rb', line 8 def initialize(root_logger, class_obj) @root_logger = root_logger @class_name = class_obj.name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/unicorn-cuba-base/root_logger.rb', line 17 def method_missing(name, *args, &block) if @@levels.include? name root_logger = @root_logger.('className' => @class_name) if block root_logger.send(name, &block) else = args.first if args.last.is_a? Exception error = args.last root_logger = root_logger.('exceptionClass' => error.class.name) = "#{message}: #{error.class.name}: #{error.message}\n#{error.backtrace.join("\n")}" end # log with class name root_logger.send(name, .chomp, &block) end else # forward to root logger @root_logger.send(name, *args, &block) end end |
Instance Attribute Details
#root_logger ⇒ Object (readonly)
Returns the value of attribute root_logger.
41 42 43 |
# File 'lib/unicorn-cuba-base/root_logger.rb', line 41 def root_logger @root_logger end |
Instance Method Details
#inspect ⇒ Object
43 44 45 |
# File 'lib/unicorn-cuba-base/root_logger.rb', line 43 def inspect "#<ClassLogger[#{@progname}] #{"0x%X" % object_id} root_logger=#{@root_logger.inspect}>" end |
#respond_to?(method) ⇒ Boolean
13 14 15 |
# File 'lib/unicorn-cuba-base/root_logger.rb', line 13 def respond_to?(method) super or @root_logger.respond_to? method end |