What is logger?

  • Rails makes use of ruby’s standard logger, Log4r, or another logger that provides a similar interface can also be substituted if you wish.
  • A logger object is made available to each of ActiveRecord, ActiveController and ActiveMailer.

How to write logger?

  • logger.info "Starting process fubar..."

Log level?

  • IThe available log levels are: :debug, :info, :warn, :error, :fatal. The ruby Logger class normally also accepts :any, but that doesn’t seem to work with rails.
  • config.log_level = :debug

Log path?

  • The log file path is relative to the RAILS_ROOT directory. Make sure that the file exists and has permissions that allow writing for the user that rails will run under.
  • config.log_path = 'log/debug.log'

Initialize logger in ruby app?

  • ActiveRecord::Base.logger = Logger.new(STDERR)
  • ActiveRecord::Base.logger = Logger.new(File.open(‘log/database.log’, ‘a’))


  RAILS_DEFAULT_LOGGER = Logger.new(“#{RAILS_ROOT}/log/#{RAILS_ENV}.log”)
rescue StandardError
    “Rails Error: Unable to access log file. Please ensure that log/#{RAILS_ENV}.log exists and 
is chmod 0666. " +
    "The log level has been raised to WARN and the output directed to STDERR until the problem 
is fixed.”

Q Is it possible to display the logs in the console rather than using the “debug.log” file?
-cd /railsapp/log
-tail -f development.log




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 )

Google+ photo

You are commenting using your Google+ 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