Write Errors To file
#1
Write Errors To file
by Me™ (aka Derk-Jan)
May 3 2006

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.


This script is mainly for developers and Beta/Alpha Testers. It contains out of two poportions. What it does: Everytime an error occurs, it will write down the error, and the time to a file. This works for ALL standard errors and file-errors. Only System/Ruby Errors can not be handled yet (altough I have an idee) This is because the classes have there own Initialize (System Error's Superclass is StandardError, StandardError's Superclass is Expetion.)

Add this above everything:

Code:
class Exception
   alias :old_init :initialize
   def initialize(arg)
       old_init(arg)
       time = Time.strftime("%a %d %b %Y, %X")
       File.open("ErrorLog.txt","a+"){ |fh| fh.puts("On <<#{time}>> the error <<#{arg}>> occured.")}
    end
end

And this in main, below the print

Code:
time = Time.strftime("%a %d %b %Y, %X")
  File.open("ErrorLog.txt","a+"){ |fh| fh.puts("On <<#{time}>> Unable to find the file #{filename}.")}

It took me quite some time to figure this out. I dont NEED credit, but I would LIKE it



(you might want to add: time = Time.now, time = time.strftime("%a %d %b %Y, %X") )
}




Users browsing this thread: 1 Guest(s)