Use logger class

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

-Bill

Mohamed Saeed wrote:

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

-Bill

Mohamed Saeed wrote:

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}"

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