Skip to content

Instantly share code, notes, and snippets.

@adamw
Created March 23, 2011 12:32
Show Gist options
  • Save adamw/883035 to your computer and use it in GitHub Desktop.
Save adamw/883035 to your computer and use it in GitHub Desktop.
# In Rails config: config.logger = RubyToSlf4jLogger.new(config.paths.log.first)
require "java"
class RubyToSlf4jLogger < Logger
include_class "org.slf4j.LoggerFactory"
def initialize(logdev)
super
@logger = LoggerFactory.getLogger("ruby")
@logger.info("Ruby -> SLF4J logger initialized")
end
def add(severity, message=nil, progname=nil, &block)
super
# Copied from super method
progname ||= @progname
if message.nil?
if block_given?
message = yield
else
message = progname
end
end
case severity
when DEBUG
@logger.debug(message)
when INFO
@logger.info(message)
when WARN
@logger.warn(message)
when ERROR
@logger.error(message)
when FATAL
@logger.error(message)
when UNKNOWN
@logger.warn(message)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment