Use logger class

Hello all,

i wanna use logger to log all errors and exceptions that occurs in run
time, so i create new file “logfile.log” and put it in /log path in
rails application and put these lines of code in environment.rb file

file = File.open("#{RAILS_ROOT}/log/logfile.log", File::WRONLY |
File::CREAT)
logger = Logger.new(file)
logger.level = Logger::ERROR

and inside actions with each part of code that is surrounded with begin
and rescue i put this line

logger.error “#{e.message}”

ex:

begin
blah blah
rescue Exception => e

logger.error “#{e.message}”

end

but logfile.log always empty.
so please anyone help me in this point
thanks in advanced

Try passing the file path to Logger.new and let it deal w/ creating the
file. File.open is unnecessary.

-Bill

On 2 Dec 2007, at 16:29, William P. wrote:

i wanna use logger to log all errors and exceptions that occurs in
begin
and rescue i put this line

logger.error “#{e.message}”

Are you sure that the logger at this point is the logger you’ve
created rather than the logger rails creates for you ?
If you want to change the logger rails creates for you, then in your
environment.rb you need to set config.logger to the instance of Logger
you create

Fred