mirror of
https://github.com/opensim/opensim.git
synced 2026-05-15 03:15:41 +08:00
Refactor log4net logger handling in script engine. (#3148)
This commit is contained in:
@@ -34,6 +34,7 @@ using System.Security.Policy;
|
||||
using System.Security.Permissions;
|
||||
using OpenSim.Region.ScriptEngine.Interfaces;
|
||||
using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
|
||||
using log4net;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
{
|
||||
@@ -51,6 +52,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
// 4. Unload AppDomain completely when all scripts in it has stopped
|
||||
//
|
||||
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private int maxScriptsPerAppDomain = 1;
|
||||
|
||||
// Internal list of all AppDomains
|
||||
@@ -138,12 +141,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" +
|
||||
AppDomainNameCount, null, ads);
|
||||
|
||||
m_scriptEngine.Log.Info("[" + m_scriptEngine.ScriptEngineName +
|
||||
"]: AppDomain Loading: " +
|
||||
AssemblyName.GetAssemblyName(
|
||||
"OpenSim.Region.ScriptEngine.Shared.dll").ToString());
|
||||
m_log.Info("[" + m_scriptEngine.ScriptEngineName +
|
||||
"]: AppDomain Loading: " +
|
||||
AssemblyName.GetAssemblyName(
|
||||
"OpenSim.Region.ScriptEngine.Shared.dll").ToString());
|
||||
AD.Load(AssemblyName.GetAssemblyName(
|
||||
"OpenSim.Region.ScriptEngine.Shared.dll"));
|
||||
"OpenSim.Region.ScriptEngine.Shared.dll"));
|
||||
|
||||
// Return the new AppDomain
|
||||
return AD;
|
||||
|
||||
@@ -25,22 +25,27 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
{
|
||||
public static class Common
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public static ScriptEngine mySE;
|
||||
|
||||
// This class just contains some static log stuff used for debugging.
|
||||
|
||||
public static void SendToDebug(string message)
|
||||
{
|
||||
mySE.Log.Info("[" + mySE.ScriptEngineName + "]: Debug: " + message);
|
||||
m_log.Info("[" + mySE.ScriptEngineName + "]: Debug: " + message);
|
||||
}
|
||||
|
||||
public static void SendToLog(string message)
|
||||
{
|
||||
mySE.Log.Info("[" + mySE.ScriptEngineName + "]: LOG: " + message);
|
||||
m_log.Info("[" + mySE.ScriptEngineName + "]: LOG: " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.CoreModules.Avatar.Currency.SampleMoney;
|
||||
@@ -35,6 +36,7 @@ using OpenSim.Region;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.ScriptEngine.Shared;
|
||||
using log4net;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
{
|
||||
@@ -63,6 +65,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
// verify what exact parameters are needed.
|
||||
//
|
||||
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private ScriptEngine myScriptEngine;
|
||||
|
||||
public EventManager(ScriptEngine _ScriptEngine, bool performHookUp)
|
||||
@@ -78,8 +82,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
|
||||
public void HookUpEvents()
|
||||
{
|
||||
myScriptEngine.Log.Info("[" + myScriptEngine.ScriptEngineName +
|
||||
"]: Hooking up to server events");
|
||||
m_log.Info("[" + myScriptEngine.ScriptEngineName +
|
||||
"]: Hooking up to server events");
|
||||
|
||||
myScriptEngine.World.EventManager.OnObjectGrab +=
|
||||
touch_start;
|
||||
@@ -293,9 +297,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
if (engine != myScriptEngine.ScriptEngineName)
|
||||
return;
|
||||
|
||||
myScriptEngine.Log.Debug("OnRezScript localID: " + localID +
|
||||
" LLUID: " + itemID.ToString() + " Size: " +
|
||||
script.Length);
|
||||
m_log.Debug("OnRezScript localID: " + localID +
|
||||
" LLUID: " + itemID.ToString() + " Size: " +
|
||||
script.Length);
|
||||
|
||||
myScriptEngine.m_ScriptManager.StartScript(localID, itemID, script,
|
||||
startParam, postOnRez);
|
||||
@@ -303,7 +307,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
|
||||
public void OnRemoveScript(uint localID, UUID itemID)
|
||||
{
|
||||
myScriptEngine.Log.Debug("OnRemoveScript localID: " + localID + " LLUID: " + itemID.ToString());
|
||||
m_log.Debug("OnRemoveScript localID: " + localID + " LLUID: " + itemID.ToString());
|
||||
myScriptEngine.m_ScriptManager.StopScript(
|
||||
localID,
|
||||
itemID
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Region.ScriptEngine.Shared;
|
||||
using log4net;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
{
|
||||
@@ -58,6 +60,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
// Not noticeable unless server is under high load.
|
||||
//
|
||||
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public ScriptEngine m_ScriptEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -211,7 +215,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
{
|
||||
EventQueueThreadClass eqtc = new EventQueueThreadClass();
|
||||
eventQueueThreads.Add(eqtc);
|
||||
//m_ScriptEngine.Log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Started new script execution thread. Current thread count: " + eventQueueThreads.Count);
|
||||
//m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Started new script execution thread. Current thread count: " + eventQueueThreads.Count);
|
||||
}
|
||||
|
||||
private void AbortThreadClass(EventQueueThreadClass threadClass)
|
||||
@@ -225,10 +229,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//m_ScriptEngine.Log.Error("[" + m_ScriptEngine.ScriptEngineName + ":EventQueueManager]: If you see this, could you please report it to Tedd:");
|
||||
//m_ScriptEngine.Log.Error("[" + m_ScriptEngine.ScriptEngineName + ":EventQueueManager]: Script thread execution timeout kill ended in exception: " + ex.ToString());
|
||||
//m_log.Error("[" + m_ScriptEngine.ScriptEngineName + ":EventQueueManager]: If you see this, could you please report it to Tedd:");
|
||||
//m_log.Error("[" + m_ScriptEngine.ScriptEngineName + ":EventQueueManager]: Script thread execution timeout kill ended in exception: " + ex.ToString());
|
||||
}
|
||||
//m_ScriptEngine.Log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Killed script execution thread. Remaining thread count: " + eventQueueThreads.Count);
|
||||
//m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Killed script execution thread. Remaining thread count: " + eventQueueThreads.Count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -346,8 +350,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
{
|
||||
if (eventQueue.Count >= EventExecutionMaxQueueSize)
|
||||
{
|
||||
m_ScriptEngine.Log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: ERROR: Event execution queue item count is at " + eventQueue.Count + ". Config variable \"EventExecutionMaxQueueSize\" is set to " + EventExecutionMaxQueueSize + ", so ignoring new event.");
|
||||
m_ScriptEngine.Log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: Event ignored: localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName);
|
||||
m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: ERROR: Event execution queue item count is at " + eventQueue.Count + ". Config variable \"EventExecutionMaxQueueSize\" is set to " + EventExecutionMaxQueueSize + ", so ignoring new event.");
|
||||
m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: Event ignored: localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
// within a class
|
||||
public class EventQueueThreadClass
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
// How many ms to sleep if queue is empty
|
||||
private static int nothingToDoSleepms;// = 50;
|
||||
private static ThreadPriority MyThreadPriority;
|
||||
@@ -110,11 +112,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
break;
|
||||
default:
|
||||
MyThreadPriority = ThreadPriority.BelowNormal;
|
||||
m_ScriptEngine.Log.Error(
|
||||
"[ScriptEngine.DotNetEngine]: Unknown "+
|
||||
"priority type \"" + pri +
|
||||
"\" in config file. Defaulting to "+
|
||||
"\"BelowNormal\".");
|
||||
m_log.Error(
|
||||
"[ScriptEngine.DotNetEngine]: Unknown "+
|
||||
"priority type \"" + pri +
|
||||
"\" in config file. Defaulting to "+
|
||||
"\"BelowNormal\".");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -186,24 +188,22 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
if (lastScriptEngine != null)
|
||||
lastScriptEngine.Log.Info("[" + ScriptEngineName +
|
||||
"]: ThreadAbortException while executing "+
|
||||
"function.");
|
||||
m_log.Info("[" + ScriptEngineName +
|
||||
"]: ThreadAbortException while executing "+
|
||||
"function.");
|
||||
}
|
||||
catch (SelfDeleteException) // Must delete SOG
|
||||
{
|
||||
SceneObjectPart part =
|
||||
lastScriptEngine.World.GetSceneObjectPart(
|
||||
lastScriptEngine.World.GetSceneObjectPart(
|
||||
lastLocalID);
|
||||
if (part != null && part.ParentGroup != null)
|
||||
lastScriptEngine.World.DeleteSceneObject(
|
||||
part.ParentGroup, false);
|
||||
part.ParentGroup, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (lastScriptEngine != null)
|
||||
lastScriptEngine.Log.ErrorFormat("[{0}]: Exception {1} thrown", ScriptEngineName, e.GetType().ToString());
|
||||
m_log.ErrorFormat("[{0}]: Exception {1} thrown", ScriptEngineName, e.GetType().ToString());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -214,10 +214,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened
|
||||
if (lastScriptEngine != null)
|
||||
lastScriptEngine.Log.ErrorFormat(
|
||||
"[{0}]: Event queue thread terminating with exception. PLEASE REBOOT YOUR SIM - SCRIPT EVENTS WILL NOT WORK UNTIL YOU DO. Exception is {1}",
|
||||
ScriptEngineName, e);
|
||||
m_log.ErrorFormat(
|
||||
"[{0}]: Event queue thread terminating with exception. PLEASE REBOOT YOUR SIM - SCRIPT EVENTS WILL NOT WORK UNTIL YOU DO. Exception is {1}",
|
||||
ScriptEngineName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,11 +341,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
m_ScriptEngine.m_EventQueueManager.
|
||||
m_ScriptEngine.Log.Error("[" +
|
||||
ScriptEngineName + "]: " +
|
||||
"Unable to send text in-world:\r\n" +
|
||||
text);
|
||||
m_log.Error("[" +
|
||||
ScriptEngineName + "]: " +
|
||||
"Unable to send text in-world:\r\n" +
|
||||
text);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
private void StopMaintenanceThread()
|
||||
{
|
||||
#if DEBUG
|
||||
//m_ScriptEngine.Log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: StopMaintenanceThread() called");
|
||||
//m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: StopMaintenanceThread() called");
|
||||
#endif
|
||||
//PleaseShutdown = true;
|
||||
Thread.Sleep(100);
|
||||
@@ -120,7 +120,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//m_ScriptEngine.Log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: Exception stopping maintenence thread: " + ex.ToString());
|
||||
//m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: Exception stopping maintenence thread: " + ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,8 +131,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
public void MaintenanceLoop()
|
||||
{
|
||||
//if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms)
|
||||
// m_ScriptEngine.Log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " +
|
||||
// "Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run.");
|
||||
// m_log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " +
|
||||
// "Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run.");
|
||||
|
||||
long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks;
|
||||
long Last_ReReadConfigFilens = DateTime.Now.Ticks;
|
||||
|
||||
@@ -98,11 +98,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
get { return "ScriptEngine.DotNetEngine"; }
|
||||
}
|
||||
|
||||
public ILog Log
|
||||
{
|
||||
get { return m_log; }
|
||||
}
|
||||
|
||||
public ScriptEngine()
|
||||
{
|
||||
// For logging, just need any instance, doesn't matter
|
||||
|
||||
@@ -240,14 +240,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
}
|
||||
catch (Exception e2) // LEGIT: User Scripting
|
||||
{
|
||||
m_scriptEngine.Log.Error("[" +
|
||||
m_scriptEngine.ScriptEngineName +
|
||||
"]: Error displaying error in-world: " +
|
||||
e2.ToString());
|
||||
m_scriptEngine.Log.Error("[" +
|
||||
m_scriptEngine.ScriptEngineName + "]: " +
|
||||
"Errormessage: Error compiling script:\r\n" +
|
||||
e2.Message.ToString());
|
||||
m_log.Error("[" +
|
||||
m_scriptEngine.ScriptEngineName +
|
||||
"]: Error displaying error in-world: " +
|
||||
e2.ToString());
|
||||
m_log.Error("[" +
|
||||
m_scriptEngine.ScriptEngineName + "]: " +
|
||||
"Errormessage: Error compiling script:\r\n" +
|
||||
e2.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,8 +258,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
if (id == null)
|
||||
return;
|
||||
|
||||
m_scriptEngine.Log.DebugFormat("[{0}]: Unloading script",
|
||||
m_scriptEngine.ScriptEngineName);
|
||||
m_log.DebugFormat("[{0}]: Unloading script",
|
||||
m_scriptEngine.ScriptEngineName);
|
||||
|
||||
// Stop long command on script
|
||||
AsyncCommandManager.RemoveScript(m_scriptEngine, localID, itemID);
|
||||
@@ -280,11 +280,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
}
|
||||
catch (Exception e) // LEGIT: User Scripting
|
||||
{
|
||||
m_scriptEngine.Log.Error("[" +
|
||||
m_scriptEngine.ScriptEngineName +
|
||||
"]: Exception stopping script localID: " +
|
||||
localID + " LLUID: " + itemID.ToString() +
|
||||
": " + e.ToString());
|
||||
m_log.Error("[" +
|
||||
m_scriptEngine.ScriptEngineName +
|
||||
"]: Exception stopping script localID: " +
|
||||
localID + " LLUID: " + itemID.ToString() +
|
||||
": " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,10 +379,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
}
|
||||
else if (item.Action == LUType.Load)
|
||||
{
|
||||
m_scriptEngine.Log.DebugFormat("[{0}]: Loading script",
|
||||
m_scriptEngine.ScriptEngineName);
|
||||
m_log.DebugFormat("[{0}]: Loading script",
|
||||
m_scriptEngine.ScriptEngineName);
|
||||
_StartScript(item.localID, item.itemID, item.script,
|
||||
item.startParam, item.postOnRez);
|
||||
item.startParam, item.postOnRez);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -414,13 +414,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||
{
|
||||
if ((LUQueue.Count >= LoadUnloadMaxQueueSize) && m_started)
|
||||
{
|
||||
m_scriptEngine.Log.Error("[" +
|
||||
m_scriptEngine.ScriptEngineName +
|
||||
"]: ERROR: Load/unload queue item count is at " +
|
||||
LUQueue.Count +
|
||||
". Config variable \"LoadUnloadMaxQueueSize\" "+
|
||||
"is set to " + LoadUnloadMaxQueueSize +
|
||||
", so ignoring new script.");
|
||||
m_log.Error("[" +
|
||||
m_scriptEngine.ScriptEngineName +
|
||||
"]: ERROR: Load/unload queue item count is at " +
|
||||
LUQueue.Count +
|
||||
". Config variable \"LoadUnloadMaxQueueSize\" "+
|
||||
"is set to " + LoadUnloadMaxQueueSize +
|
||||
", so ignoring new script.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user