From 888151833b1b08a6a8686d75a0385232b7fa90e9 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Tue, 9 Dec 2008 03:06:26 +0000 Subject: * Added primitive exception logging capabilities. * Disabled by default (see OpenSim.ini.example for how to enable) * Saves exceptions to a folder on disk (default "crashes") when enabled. * These reports can then be uploaded or posted to help debug an error. --- OpenSim/Framework/Util.cs | 28 ++++++++++++++++++++++++++++ OpenSim/Region/Application/Application.cs | 29 ++++++++++++++++++++--------- bin/OpenSim.ini.example | 9 +++++++++ 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index c1429df..23bdb94 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -560,6 +560,34 @@ namespace OpenSim.Framework return "."; } + // From: http://coercedcode.blogspot.com/2008/03/c-generate-unique-filenames-within.html + public static string GetUniqueFilename(string FileName) + { + int count = 0; + string Name; + + if (File.Exists(FileName)) + { + FileInfo f = new FileInfo(FileName); + + if (!string.IsNullOrEmpty(f.Extension)) + { + Name = f.FullName.Substring(0, f.FullName.LastIndexOf('.')); + } + else + { + Name = f.FullName; + } + + while (File.Exists(FileName)) + { + count++; + FileName = Name + count + f.Extension; + } + } + return FileName; + } + // Nini (config) related Methods public static IConfigSource ConvertDataRowToXMLConfig(DataRow row, string fileName) { diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs index c891549..08dd7df 100644 --- a/OpenSim/Region/Application/Application.cs +++ b/OpenSim/Region/Application/Application.cs @@ -26,6 +26,7 @@ */ using System; +using System.IO; using System.Net; using System.Reflection; using log4net; @@ -42,6 +43,9 @@ namespace OpenSim public static string iniFilePath = ""; + public static bool m_saveCrashDumps = false; + public static string m_crashDir = "crashes"; + //could move our main function into OpenSimMain and kill this class public static void Main(string[] args) { @@ -84,6 +88,9 @@ namespace OpenSim bool background = configSource.Configs["Startup"].GetBoolean("background", false); bool hgrid = configSource.Configs["Startup"].GetBoolean("hypergrid", false); + m_saveCrashDumps = configSource.Configs["Startup"].GetBoolean("save_crashes", false); + m_crashDir = configSource.Configs["Startup"].GetString("crash_dir", m_crashDir); + if (background) { OpenSimBase sim = new OpenSimBackground(configSource); @@ -139,19 +146,23 @@ namespace OpenSim m_log.ErrorFormat("[APPLICATION]: {0}", msg); - // Try to post errormessage to an URL + // Log exception to disk try { - // DISABLED UNTIL WE CAN DISCUSS IF THIS IS MORALLY RIGHT OR NOT - // Note! Needs reference to System.Web - //System.Net.WebClient wc = new WebClient(); - //wc.DownloadData("http://www.opensimulator.org/ErrorReport.php?Msg=" + - // System.Web.HttpUtility.UrlEncode(msg)); - //wc.Dispose(); + if (!Directory.Exists(m_crashDir)) + { + Directory.CreateDirectory(m_crashDir); + } + StreamWriter m_crashLog = + new StreamWriter( + Path.Combine(m_crashDir, Util.GetUniqueFilename(ex.GetType() + ".txt")) + ); + m_crashLog.WriteLine(msg); + m_crashLog.Close(); } - catch (WebException) + catch (Exception e2) { - // Ignore + m_log.ErrorFormat("[CRASH LOGGER CRASHED]: {0}", e2); } _IsHandlingException=false; diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index eeb8f04..b3c7199 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -1,4 +1,13 @@ [Startup] +; Set this to true if you want to log crashes to disk +; this can be useful when submitting bug reports. +save_crashes = false + +; Directory to save crashes to if above is enabled +; (eg default is /opensimdir/crashes/*.txt or C:\opensim\crashes\*.txt) +crash_dir = "crashes" + + ; Set this to true if you are connecting your OpenSimulator regions to a grid ; Set this to false if you are running OpenSimulator in standalone mode gridmode = false -- cgit v1.1