Search code examples
ruby-on-railstomcatloggingjruby

Jruby on Rails logging with Tomcat


I have a jruby/rails (4.1) app that I want to deploy through Tomcat. I made the app log through stdout by adding

    config.logger = Logger.new(STDOUT)

in config/application.rb, and the log lines are going to catalina.log.

We would like the app logs to go to a separate Tomcat logfile. Is it possible? how can it be configured?

Thanks!


Solution

  • if you do not set config.logger at all ... it will log to where servlet log goes

    so simply do not do anything at all with config.logger (just leave the default) and it should work (assuming JRuby-Rack of course). otherwise there are 2 options :

    • use a Java logging library (in case of TC that is either JUL or Log4J) and configure JRuby-Rack to delegate

    • or simply config.logger = Logger.new('logs/rails.log') in this case make sure you set a formatter to include timestamps

    NOTE: be aware that in the first case the Java logging library will receive all logs from Rails at the info level (loggers are not mapped "1-to-1") ... this might change in a future JRuby-Rack 1.2 release.