Chronicling My Ruby on Rails Journey

April 12, 2007

Ever wonder how to write to Rails log files?

Filed under: rails — Bob Ngu @ 9:51 am

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 Comments »

  1. Thanks! This helped me out.

    Comment by ngzax — June 22, 2007 @ 3:53 am | Reply

  2. Thanks !

    Comment by erwan — July 8, 2007 @ 11:49 pm | Reply

  3. Thanks
    thats saved some googling time

    Comment by P — February 28, 2008 @ 4:07 am | Reply

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

    Many thanks

    Doug M

    Comment by Doug M — July 7, 2008 @ 8:06 pm | Reply

  5. Thanks!

    Comment by Juan — February 13, 2009 @ 11:13 am | Reply

  6. 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!

    Comment by Tony Adams — April 15, 2009 @ 7:13 am | Reply

  7. Thanks!!!

    Comment by Nnanna — May 27, 2009 @ 7:11 am | Reply

  8. 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

    Comment by kikito — August 31, 2009 @ 5:08 am | Reply

  9. 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.

    Comment by Martin — October 30, 2009 @ 2:51 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.