Created
March 23, 2011 12:32
-
-
Save adamw/883035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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