Chronicling My Ruby on Rails Journey

Ever wonder how to write to Rails log files?

Posted by: Bob Ngu on: April 12, 2007

My RoR efforts have culminated in JiggyMe, check it out!

You can do it like this using RAILS_DEFAULT_LOGGER.error, e.g.,

RAILS_DEFAULT_LOGGER.error("\n test \n")

This writes to one of 3 logs: development, test, production depending on what mode you are in when you executed the code. Enjoy!

Updated 10.30.2009
From one of the commenter

Since rails 2.1, there’s a more convenient way to log:

logger.debug ‘message’

You can use the following methods on logger: debug, info, warn, error, and fatal.

9 Responses to "Ever wonder how to write to Rails log files?"

Thanks! This helped me out.

Thanks !

Thanks
thats saved some googling time

Simple post but just what I wanted and it works just like I hoped.

Many thanks

Doug M

Yes! This may be a tiny post, but as others have noted, it is exactly what we need at the moment. I’ve been programming for years but as a newbie to Ruby and Rails – much of the beauty of it was giving me the illusion that everything would be easy -of course that is never the case. Eventually one has to roll up one’s sleeves and revise some code.

Without a view into the black box I was starting to get a bit frustrated.

Thanks a ton for posting this!

Since rails 2.1, there’s a more convenient way to log:

logger.debug ‘message’

You can use the following methods on logger: debug, info, warn, error, and fatal.

More info on http://maintainable.com/articles/rails_logging_tips

If you use Textmate there is a snippet you can call on by typing rdb and hitting tab.
This will type RAILS_DEFAULT_LOGGER.debug “message” for you.

Leave a Reply