尝试将错误日志记录到 Ruby 程序中,这样当我遇到错误时,我可以运行该程序,它会自动将错误写入文本文件。我能够将所有内容写入文件,但每次我在其中输入新错误时都会覆盖文件,并且一次只能保存一个条目。
到目前为止,这是我的代码:
print "What is the error message? "
msg = "Error message: " + gets.chomp
print "What does the error mean? "
mean = "Error meaning: "+gets.comp
print "What resolved the error? "
resolved = "Error resolution: " + gets.comp
File.open('Bug_Log.txt', 'w') do |write|
write.puts msg
write.puts mean
write.puts resolved
end