diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index c1429df771..23bdb942a4 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 c891549fe3..08dd7df875 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 eeb8f04d9b..b3c71990de 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