# Rails Logging

**URL:** <https://www.ruby-forum.com/t/rails-logging/211344>\
**Category:** JRuby\
**Created:** [September 1, 2011, 10:28pm UTC](https://www.ruby-forum.com/t/rails-logging/211344 "2011-09-01T22:28:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [September 1, 2011, 10:28pm UTC](https://www.ruby-forum.com/t/rails-logging/211344/1 "2011-09-01T22:28:18Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![ericdfields](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@ericdfields](https://www.ruby-forum.com/u/ericdfields)\
**Post date:** [September 1, 2011, 10:43pm UTC](https://www.ruby-forum.com/t/rails-logging/211344/2 "2011-09-01T22:43:44Z")

</div>

On Thu, Sep 1, 2011 at 3:26 PM, Eric F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![ericdfields](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@ericdfields](https://www.ruby-forum.com/u/ericdfields)\
**Post date:** [September 1, 2011, 10:49pm UTC](https://www.ruby-forum.com/t/rails-logging/211344/3 "2011-09-01T22:49:18Z")

</div>

On Thu, Sep 1, 2011 at 3:43 PM, Anthony J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
