class RJack::SLF4J::Logger
Ruby ::Logger compatible adapter for org.slf4j.Logger
Generated Methods¶ ↑
Corresponding methods are generated for each of the SLF4J levels:
-
trace
-
debug
-
info
-
warn
-
error
-
fatal (alias to error)
These have the form (using info as example):
log = Logger.new( "name" ) log.info? # Is this level enabled for logging? log.info( "message" ) # Log message log.info { "message" } # Execute block if enabled and log returned value log.info( "message", ex ) # Log message with exception message/stack trace log.info( ex ) { "message" } # Log message with exception message/stack trace log.info( ex ) # Log exception with default "Exception:" message
Note that the exception variants are aware of JRuby's NativeException class (a wrapped java exception) and will log using the Java ex.cause in this case.
Attributes
Unused attribute, for Ruby ::Logger compatibility.
Unused attribute, for Ruby ::Logger compatibility.
Unused attribute, for Ruby ::Logger compatibility.
Unused attribute, for Ruby ::Logger compatibility.
Unused attribute, for Ruby ::Logger compatibility.
Public Class Methods
Create new or find existing Logger by name. If name is a Module (Class, etc.) then use RJack::SLF4J.to_log_name( name ) as the name
Note that loggers are arranged in a hiearchy by dot '.' name notation using java package/class name conventions:
-
“pmodule”
-
“pmodule.cmodule.”
-
“pmodule.cmodule.ClassName”
Which enables hierarchical level setting and abbreviation in some output adapters.
# File lib/rjack-slf4j.rb, line 207 def initialize( name ) @name = name.is_a?( Module ) ? SLF4J.to_log_name( name ) : name @logger = org.slf4j.LoggerFactory.getLogger( @name ) @level = 0 #DEBUG end
Public Instance Methods
Log via Ruby ::Logger levels, for compatibility. UNKNOWN or nil level is mapped to info
# File lib/rjack-slf4j.rb, line 315 def add( rlvl, msg = nil, progname = nil, &block ) case rlvl when 0 #DEBUG debug( msg, &block ) when 1 #INFO info( msg, &block ) when 2 #WARN warn( msg, &block ) when 3 #ERROR error( msg, &block ) when 4 #FATAL error( msg, &block ) else #UNKNOWN, nil info( msg, &block ) end end
No-Op, for Ruby ::Logger compatibility.
# File lib/rjack-slf4j.rb, line 335 def close #No-OP end
Unused attribute, for Ruby ::Logger compatibility.
# File lib/rjack-slf4j.rb, line 287 def datetime_format=( v ) debug { "Setting SLF4J::Logger datetime_format=#{v.inspect} has no effect" } @datetime_format = v end
Unused attribute, for Ruby ::Logger compatibility.
# File lib/rjack-slf4j.rb, line 296 def formatter=( v ) debug { "Setting SLF4J::Logger formatter=#{v.inspect} has no effect" } @formatter = v end
Return underlying org.slf4j.Logger
# File lib/rjack-slf4j.rb, line 214 def java_logger @logger end
Unused attribute, for Ruby ::Logger compatibility.
# File lib/rjack-slf4j.rb, line 274 def level=( v ) debug { "Setting SLF4J::Logger level=#{v.inspect} has no effect" } @level = v end
Unused attribute, for Ruby ::Logger compatibility.
# File lib/rjack-slf4j.rb, line 265 def progname=( v ) debug { "Setting SLF4J::Logger progname=#{v.inspect} has no effect" } @progname = v end
No-Op, for Ruby ::Logger compatibility.
# File lib/rjack-slf4j.rb, line 340 def reopen end