Rails makes use of ruby's standard "logger":http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/index.html From within a controller:
logger.debug "user.id = #{user.id}"
logger.info "Starting process fubar..."
logger.warn "No results found for XYZ"
logger.error err.message
logger.fatal "Database down"
From within a view:
@logger.debug "user.id = #{user.id}"
(This will hopefully be rationalised in a future version of Rails.)
Finally, there's a constant @RAILS_DEFAULT_LOGGER@ which can be used from anywhere, including the console.
In summary:
Model View Controller Console
@logger - X - -
logger X - X -
RAILS_DEFAULT_LOGGER X X X X
Model View Controller Console
logger X X X X
but that's not the way it works at the moment (2005-04-21).
class ApplicationController < ActionController::Base
helper_method :logger
end
See also HowtoConfigureLogging.
category: Howto