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
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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}" > > 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 >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Dec 2007, at 16:29, William Pratt 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>> 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 >> > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---