Morten,

At great risk of opening a java logging APIs debate, you might consider
using the slf4j and logback gems (http://rjack.rubyforge.org/) for your
logging needs. 

In particular, the combination supports aggregating logging from all
common APIs/sources including java.util.logging, and logging from ruby
is via a ruby-core Logger compatible adapter to SLF4J, and slf4j/logback
doesn't insist on using callers java class name in the output:

require 'rubygems'
require 'logback'

Logback.config_console( :full => true )

log = SLF4J['com.test.xxx']
log.info 'logging from jruby'

2009-05-08 14:40:05,382 INFO  com.test.xxx - logging from jruby

BTW: slf4j -> java.util.logging shows the same NativeMethodAccessorImpl
class name. Not sure if you can replace that field in the output with a
given name instead (like with logback,log4j, etc.) I doubt this is a
jruby problem per say.

--David

On Thu, 2009-05-07 at 06:47 -0500, Morten Christensen (JIRA) wrote:

> java.util.logging misbehavior when called from JRuby
> ----------------------------------------------------
> 
>                  Key: JRUBY-3628
>                  URL: http://jira.codehaus.org/browse/JRUBY-3628
>              Project: JRuby
>           Issue Type: Bug
>           Components: Core Classes/Modules, Java Integration
>     Affects Versions: JRuby 1.2
>          Environment: Java 1.6, JRuby 1.2
>             Reporter: Morten Christensen
> l
> 
> When calling Java's java.util.logging system within Jruby, the logger name is 
> wrongly set to "sun.reflect.NativeMethodAccessorImpl" instead of the logger 
> name specified by the call to Logger. Apart from making things difficult when 
> reading the log, this also cause the normal java log filters to malfunction 
> (i.e the log messages from jruby may not appear unless a special/default log 
> level is set to log sun.reflect also). This is a major problem with 
> java/jruby projects, as proper logging behavior is essential for production 
> systems!
> 
> To reproduce try this under IRB:
> log = java.util.logging.Logger.getLogger('com.test.xxx')
> log.addHandler(java.util.logging.ConsoleHandler.new())
> log.log(java.util.logging.Level::SEVERE, 'Logging from JRuby')
> 
> The correct result would be something like:
> May 7, 2009 1:31:13 PM com.test.xx ???
> SEVERE: Logging from JRuby
> 
> But JRuby 1.2 incorrectly writes: 
> May 7, 2009 1:31:13 PM sun.reflect.NativeMethodAccessorImpl invoke0
> SEVERE: Logging from JRuby
> 
> 

Reply via email to