maandag 27 april 2009

Ruby On Rails: Write to log

A good thing about Rails is the logs that are produced. In development mode rails will list out all SQL statements and trace all controller calls.

It is possible to add custom messages to the Rails log through in a single line command. The RAILS_DEFAULT_LOGGER object, which is defined in environment.rb, makes this possible.

The RAILS_DEFAULT_LOGGER object supports the following log levels:
* debug
* info
* warn
* error
* fatal

To add debug calls to your code for development mode just add the following:


RAILS_DEFAULT_LOGGER.info "Your log message"