class RJack::SLF4J::Logger

Ruby ::Logger compatible adapter for org.slf4j.Logger

Generated Methods

Corresponding methods are generated for each of the SLF4J levels:

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

datetime_format[R]

Unused attribute, for Ruby ::Logger compatibility.

formatter[R]

Unused attribute, for Ruby ::Logger compatibility.

level[R]

Unused attribute, for Ruby ::Logger compatibility.

name[R]
progname[R]

Unused attribute, for Ruby ::Logger compatibility.

sev_threshold[R]

Unused attribute, for Ruby ::Logger compatibility.

Public Class Methods

new( name ) click to toggle source

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

add( rlvl, msg = nil, progname = nil, &block ) click to toggle source

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
Also aliased as: log
close() click to toggle source

No-Op, for Ruby ::Logger compatibility.

# File lib/rjack-slf4j.rb, line 335
def close
  #No-OP
end
datetime_format=( v ) click to toggle source

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
formatter=( v ) click to toggle source

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
java_logger() click to toggle source

Return underlying org.slf4j.Logger

# File lib/rjack-slf4j.rb, line 214
def java_logger
  @logger
end
level=( v ) click to toggle source

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
Also aliased as: sev_threshold=
log( rlvl, msg = nil, progname = nil, &block )
Alias for: add
progname=( v ) click to toggle source

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
reopen() click to toggle source

No-Op, for Ruby ::Logger compatibility.

# File lib/rjack-slf4j.rb, line 340
def reopen
end
sev_threshold=( v )
Alias for: level=