Error Log and its uses!
If you receive any error in any part of the game, this script will capture it, and record it.
Useful for using it in compiled games, testing released scripts and just for having records of the errors you have received.
Instead of asking the players/testers/users for re-acting the error(s), you can just ask them send you this detailed file saved in their game's folder.
I made this little script for a project of mine.
Features
Example Output
Cons
If an error is from an hidden class or a class that overrides a hidden class, the line and method will not be shown, however, all other data will be present(such as original error line and script name). It would be very rare to have errors originate from hidden classes, so this is not bad.
Installing in 10 seconds
Open your Script Editor and go to Main. put a "begin" over all the way to the top, where the other begin is:
Snippet - Should look similar to this with 2 'begin'
Now, go all the way to end of that script(after end) and copy and paste this:
The whole thing should probably look like this:
Finally
Once an error appears, the player sees this line:
print "Unexpected Error! Please visit http://www.site.com/support for more info.\n"+
"The ErrorLog is in folder:\n #{File.expand_path('.')}"
Which might not be what you want the player to see. So what you can do is, change it :-p. Here is an example of a different one:
print "Unexpected Error! The ErrorLog is in folder:\n #{File.expand_path('.')}"
However, in Debug(Test Play), the message displays the error, error line and method.
To open the ErrorLog.rxdata file and see the errors:
1) Right Click
2) Open With
3) Note Pad
Credits
Credit to me. Feel free to use it in any project(commercial or not) as long as I'm mentioned.
If you receive any error in any part of the game, this script will capture it, and record it.
Useful for using it in compiled games, testing released scripts and just for having records of the errors you have received.
Instead of asking the players/testers/users for re-acting the error(s), you can just ask them send you this detailed file saved in their game's folder.
I made this little script for a project of mine.
Features
- Records error message and type.
- Records scripts with the error, error line, and method.
- It traces the origination of the error to the line where the error is shown.
- Records Date and Time.
Example Output
Code:
[COLOR=Blue][ Sun 25 Nov 2007, 01:12:44 ][/COLOR]
[COLOR=Red]'undefined method `values' for nil:NilClass' Type NoMethodError[/COLOR][COLOR=Green]
<>Script '[LIB] Network Library' | Line 169 | Method `update'[/COLOR]
<>Script 'Scene_Title' | Line 71 | Method `main'
<>Script 'Scene_Title' | Line 69 | Method `loop'
<>Script 'Scene_Title' | Line 82 | Method `main'
- First Line: Date and Time
- Second Line: The error message and type
- Third line: The line where the error is.
- Other lines: The lines where the data originated from, not the error.
Cons
If an error is from an hidden class or a class that overrides a hidden class, the line and method will not be shown, however, all other data will be present(such as original error line and script name). It would be very rare to have errors originate from hidden classes, so this is not bad.
Installing in 10 seconds
Open your Script Editor and go to Main. put a "begin" over all the way to the top, where the other begin is:
Snippet - Should look similar to this with 2 'begin'
Code:
#==============================================================================
# ** Main
#------------------------------------------------------------------------------
# After defining each class, actual processing begins here.
#==============================================================================
[B]begin
begin[/B]
# Prepare for transition
Graphics.freeze
# Make scene object (title screen)
$scene = Scene_Title.new
Now, go all the way to end of that script(after end) and copy and paste this:
Code:
rescue
# Record Error
k = 0
time = Time.now
time = time.strftime("%a %d %b %Y, %X")
log = File.open("ErrorLog.rxdata","a+")
log.write("[ #{time} ]\n")
# Write Message and Type
log.write("'#{$!.message}' Type #{$!.class}\n")
for i in 0..$!.backtrace.size
e = $!.backtrace[i]
/Section(.*):(.*):in (.*)/.match(e)
space = " "*(i*2)
log.write(space+" <>Script '#{$RGSS_SCRIPTS[$1.to_i][1]}' | Line #{$2} | Method #{$3}\n")
i += 1
# Don't list more then 4 backtraces to make it simpler, can be changed!
break if i >= 4
next if k == 1
# Get the first trace
script = "#{$RGSS_SCRIPTS[$1.to_i][1]}"
line = $2
method = $3
k = 1
end
log.write("\n")
log.close
# Make some sense
if $DEBUG
print "#{$!.message} \nScript '#{script}' \nLine '#{line}' \nMethod '#{method}' \nType '#{$!.class}'"
else
print "Unexpected Error! Please visit www.site.com/support for more info.\n"+
"The ErrorLog is in folder:\n #{File.expand_path('.')}"
end
end
The whole thing should probably look like this:
Code:
#==============================================================================
# ** Main
#------------------------------------------------------------------------------
# After defining each class, actual processing begins here.
#==============================================================================
[COLOR=Blue][B]begin[/B][/COLOR]
begin
# Prepare for transition
Graphics.freeze
# Make scene object (title screen)
$scene = Scene_Title.new
# Call main method as long as $scene is effective
while $scene != nil
$scene.main
end
# Fade out
Graphics.transition(20)
rescue Errno::ENOENT
# Supplement Errno::ENOENT exception
# If unable to open file, display message and end
filename = $!.message.sub("No such file or directory - ", "")
print("Unable to find file #{filename}.")
end[COLOR=Blue][B]
rescue
# Record Error
k = 0
time = Time.now
time = time.strftime("%a %d %b %Y, %X")
log = File.open("ErrorLog.rxdata","a+")
log.write("[ #{time} ]\n")
# Write Message and Type
log.write("'#{$!.message}' Type #{$!.class}\n")
for i in 0..$!.backtrace.size
e = $!.backtrace[i]
/Section(.*):(.*):in (.*)/.match(e)
space = " "*(i*2)
log.write(space+" <>Script '#{$RGSS_SCRIPTS[$1.to_i][1]}' | Line #{$2} | Method #{$3}\n")
i += 1
# Don't list more then 4 backtraces to make it simpler, can be changed!
break if i >= 4
next if k == 1
# Get the first trace
script = "#{$RGSS_SCRIPTS[$1.to_i][1]}"
line = $2
method = $3
k = 1
end
log.write("\n")
log.close
# Make some sense
if $DEBUG
print "#{$!.message} \nScript '#{script}' \nLine '#{line}' \nMethod '#{method}' \nType '#{$!.class}'"
else
print "Unexpected Error! Please visit www.site.com/support for more info.\n"+
"The ErrorLog is in folder:\n #{File.expand_path('.')}"
end
end[/B][/COLOR]
Finally
Once an error appears, the player sees this line:
print "Unexpected Error! Please visit http://www.site.com/support for more info.\n"+
"The ErrorLog is in folder:\n #{File.expand_path('.')}"
Which might not be what you want the player to see. So what you can do is, change it :-p. Here is an example of a different one:
print "Unexpected Error! The ErrorLog is in folder:\n #{File.expand_path('.')}"
However, in Debug(Test Play), the message displays the error, error line and method.
To open the ErrorLog.rxdata file and see the errors:
1) Right Click
2) Open With
3) Note Pad
Credits
Credit to me. Feel free to use it in any project(commercial or not) as long as I'm mentioned.