Class: Telekinesis::Logging::RubyLoggerHandler
- Inherits:
-
Handler
- Object
- Handler
- Telekinesis::Logging::RubyLoggerHandler
- Defined in:
- lib/telekinesis/logging/ruby_logger_handler.rb
Overview
A java logging Handler that delegates to a Ruby logger. The name of the j.u.l. logger is used as the progname argument to Logger.add.
The translation between j.u.l. serverity levels and Ruby Logger levels isn’t exact.
Constant Summary collapse
- SEVERITY =
{ # NOTE: There's no Java equivalent of FATAL. Level::SEVERE => Logger::ERROR, Level::WARNING => Logger::WARN, Level::INFO => Logger::INFO, Level::CONFIG => Logger::INFO, Level::FINE=> Logger::DEBUG, Level::FINER=> Logger::DEBUG, Level::FINEST=> Logger::DEBUG, }
Class Method Summary collapse
-
.create(logger) ⇒ Object
NOTE: Since this class overrides a Java class, we have to use the Java constructor and set the logger after instantiation.
Instance Method Summary collapse
- #close ⇒ Object
-
#flush ⇒ Object
Ruby’s logger has no flush method.
- #publish(log_record) ⇒ Object
- #set_logger(l) ⇒ Object
Class Method Details
.create(logger) ⇒ Object
NOTE: Since this class overrides a Java class, we have to use the Java constructor and set the logger after instantiation. (Overriding in JRuby is weird). Use this method to create a new logger that delegates to the passed logger.
16 17 18 19 20 |
# File 'lib/telekinesis/logging/ruby_logger_handler.rb', line 16 def self.create(logger) new.tap do |s| s.set_logger(logger) end end |
Instance Method Details
#close ⇒ Object
37 38 39 |
# File 'lib/telekinesis/logging/ruby_logger_handler.rb', line 37 def close @logger.close end |
#flush ⇒ Object
Ruby’s logger has no flush method.
42 |
# File 'lib/telekinesis/logging/ruby_logger_handler.rb', line 42 def flush; end |
#publish(log_record) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/telekinesis/logging/ruby_logger_handler.rb', line 44 def publish(log_record) = if log_record.thrown.nil? log_record. else "#{log_record.}: #{log_record.thrown}" end @logger.add(SEVERITY[log_record.level], , log_record.logger_name) end |
#set_logger(l) ⇒ Object
33 34 35 |
# File 'lib/telekinesis/logging/ruby_logger_handler.rb', line 33 def set_logger(l) @logger = l end |