Forum: JRuby Rails Logging

0b3111864eaf5cd1936b91bb166b1301?d=identicon&s=25 Eric Fleming (Guest)
on 2011-09-01 22:28
(Received via mailing list)
I am trying to get logging under control in my rails app when running
locally.  I have a jar that has a lot of functionality that calls
external
services, interacts with databases, etc.  I would like to be able to set
the
log levels in the dev environment to something different in prod.  My
rails
logging works fine, but I am unable to change to log level in the java
classes from anything but INFO.  I have tried adding an initializer to
set
the level to FINE but it doesn't have any effect.  Any help would be
appreciated.

java::util::logging::Logger.getLogger("").setLevel(java::util::logging::Level::FINE)
1273e5c266e0c4cc4065fff3a6fe7056?d=identicon&s=25 Anthony Juckel (Guest)
on 2011-09-01 22:43
(Received via mailing list)
On Thu, Sep 1, 2011 at 3:26 PM, Eric Fleming <efleming@gmail.com> wrote:
[..snip..]
> classes from anything but INFO. I have tried adding an initializer to set
> the level to FINE but it doesn't have any effect. Any help would be
> appreciated.
>
java::util::logging::Logger.getLogger("").setLevel(java::util::logging::Level::FINE)

Are you certain that the jar is using the java.util.logging API, and
not one of the myriad other Java logging options?

Assuming it is using JUL, try the following to update all currently
registered loggers:

import 'java.util.logging.LogManager'
import 'java.util.logging.Level'

lm = LogManager.log_manager
lm.logger_names.each do |name|
  lm.get_logger(name).level = Level::FINE
end
1273e5c266e0c4cc4065fff3a6fe7056?d=identicon&s=25 Anthony Juckel (Guest)
on 2011-09-01 22:49
(Received via mailing list)
On Thu, Sep 1, 2011 at 3:43 PM, Anthony Juckel <ajuckel@gmail.com>
wrote:
> Assuming it is using JUL, try the following to update all currently
> registered loggers:
>
> import 'java.util.logging.LogManager'
> import 'java.util.logging.Level'
>
> lm = LogManager.log_manager
> lm.logger_names.each do |name|
> lm.get_logger(name).level = Level::FINE
> end
>

Forgot to mention that you may want to update the associated handlers
too (since they can also filter out messages):

import 'java.util.logging.LogManager'
import 'java.util.logging.Level'

lm = LogManager.log_manager
lm.logger_names.each do |name|
  l = lm.get_logger(name)
  l.level = Level::FINE
  l.handlers.each do |h|
    h.level = Level::FINE
  end
end
This topic is locked and can not be replied to.