Refactor log4net logger handling in script engine. (#3148)

This commit is contained in:
Jeff Ames
2009-02-22 01:26:18 +00:00
parent 99b051ccbe
commit 818af9d482
18 changed files with 141 additions and 133 deletions

View File

@@ -32,6 +32,7 @@ using System.Runtime.Remoting.Lifetime;
using System.Text;
using System.Threading;
using Nini.Config;
using log4net;
using OpenMetaverse;
using OpenMetaverse.Packets;
using OpenSim;
@@ -80,7 +81,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
private bool m_automaticLinkPermission=false;
private IMessageTransferModule m_TransferModule = null;
//private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
{

View File

@@ -26,6 +26,7 @@
*/
using System;
using log4net;
using OpenMetaverse;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.CoreModules.Scripting.WorldComm;
@@ -37,7 +38,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
{
public class Listener
{
// private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public AsyncCommandManager m_CmdManager;

View File

@@ -29,10 +29,12 @@ using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.IO;
using Microsoft.CSharp;
using Microsoft.JScript;
using Microsoft.VisualBasic;
using log4net;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.ScriptEngine.Interfaces;
@@ -40,8 +42,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
{
public class Compiler : ICompiler
{
// private static readonly log4net.ILog m_log
// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// * Uses "LSL2Converter" to convert LSL to C# if necessary.
// * Compiles C#-code into an assembly
@@ -126,7 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
AllowedCompilers.Clear();
#if DEBUG
m_scriptEngine.Log.Debug("[Compiler]: Allowed languages: " + allowComp);
m_log.Debug("[Compiler]: Allowed languages: " + allowComp);
#endif
@@ -135,18 +136,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
string strlan = strl.Trim(" \t".ToCharArray()).ToLower();
if (!LanguageMapping.ContainsKey(strlan))
{
m_scriptEngine.Log.Error("[Compiler]: Config error. Compiler is unable to recognize language type \"" + strlan + "\" specified in \"AllowedCompilers\".");
m_log.Error("[Compiler]: Config error. Compiler is unable to recognize language type \"" + strlan + "\" specified in \"AllowedCompilers\".");
}
else
{
#if DEBUG
//m_scriptEngine.Log.Debug("[Compiler]: Config OK. Compiler recognized language type \"" + strlan + "\" specified in \"AllowedCompilers\".");
//m_log.Debug("[Compiler]: Config OK. Compiler recognized language type \"" + strlan + "\" specified in \"AllowedCompilers\".");
#endif
}
AllowedCompilers.Add(strlan, true);
}
if (AllowedCompilers.Count == 0)
m_scriptEngine.Log.Error("[Compiler]: Config error. Compiler could not recognize any language in \"AllowedCompilers\". Scripts will not be executed!");
m_log.Error("[Compiler]: Config error. Compiler could not recognize any language in \"AllowedCompilers\". Scripts will not be executed!");
// Default language
string defaultCompileLanguage = m_scriptEngine.Config.GetString("DefaultCompileLanguage", "lsl").ToLower();
@@ -154,7 +155,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
// Is this language recognized at all?
if (!LanguageMapping.ContainsKey(defaultCompileLanguage))
{
m_scriptEngine.Log.Error("[Compiler]: " +
m_log.Error("[Compiler]: " +
"Config error. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is not recognized as a valid language. Changing default to: \"lsl\".");
defaultCompileLanguage = "lsl";
}
@@ -162,13 +163,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
// Is this language in allow-list?
if (!AllowedCompilers.ContainsKey(defaultCompileLanguage))
{
m_scriptEngine.Log.Error("[Compiler]: " +
"Config error. Default language \"" + defaultCompileLanguage + "\"specified in \"DefaultCompileLanguage\" is not in list of \"AllowedCompilers\". Scripts may not be executed!");
m_log.Error("[Compiler]: " +
"Config error. Default language \"" + defaultCompileLanguage + "\"specified in \"DefaultCompileLanguage\" is not in list of \"AllowedCompilers\". Scripts may not be executed!");
}
else
{
#if DEBUG
// m_scriptEngine.Log.Debug("[Compiler]: " +
// m_log.Debug("[Compiler]: " +
// "Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language.");
#endif
// LANGUAGE IS IN ALLOW-LIST
@@ -194,7 +195,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
}
catch (Exception ex)
{
m_scriptEngine.Log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + ScriptEnginesPath + "\": " + ex.ToString());
m_log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + ScriptEnginesPath + "\": " + ex.ToString());
}
}
@@ -208,7 +209,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
}
catch (Exception ex)
{
m_scriptEngine.Log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + Path.Combine(ScriptEnginesPath,
m_log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + Path.Combine(ScriptEnginesPath,
m_scriptEngine.World.RegionInfo.RegionID.ToString())+ "\": " + ex.ToString());
}
}
@@ -216,7 +217,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
foreach (string file in Directory.GetFiles(Path.Combine(ScriptEnginesPath,
m_scriptEngine.World.RegionInfo.RegionID.ToString())))
{
//m_scriptEngine.Log.Error("[Compiler]: FILE FOUND: " + file);
//m_log.Error("[Compiler]: FILE FOUND: " + file);
if (file.ToLower().StartsWith(FilePrefix + "_compiled_") ||
file.ToLower().StartsWith(FilePrefix + "_source_"))
@@ -227,12 +228,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
}
catch (Exception ex)
{
m_scriptEngine.Log.Error("[Compiler]: Exception trying delete old script file \"" + file + "\": " + ex.ToString());
m_log.Error("[Compiler]: Exception trying delete old script file \"" + file + "\": " + ex.ToString());
}
}
}
}
////private ICodeCompiler icc = codeProvider.CreateCompiler();
@@ -293,9 +292,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
if (Script == String.Empty)
{
if (File.Exists(OutFile))
{
// m_scriptEngine.Log.DebugFormat("[Compiler] Returning existing assembly for {0}", asset);
// m_log.DebugFormat("[Compiler] Returning existing assembly for {0}", asset);
return OutFile;
}
@@ -345,7 +343,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
//
if (File.Exists(OutFile) && File.Exists(OutFile+".text"))
{
// m_scriptEngine.Log.DebugFormat("[Compiler] Returning existing assembly for {0}", asset);
// m_log.DebugFormat("[Compiler] Returning existing assembly for {0}", asset);
return OutFile;
}
@@ -465,9 +463,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
}
catch (Exception ex) //NOTLEGIT - Should be just FileIOException
{
m_scriptEngine.Log.Error("[Compiler]: Exception while "+
"trying to write script source to file \"" +
srcFileName + "\": " + ex.ToString());
m_log.Error("[Compiler]: Exception while "+
"trying to write script source to file \"" +
srcFileName + "\": " + ex.ToString());
}
}
@@ -577,7 +575,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
errtext += "No compile error. But not able to locate compiled file.";
throw new Exception(errtext);
}
// m_scriptEngine.Log.DebugFormat("[Compiler] Compiled new assembly "+
// m_log.DebugFormat("[Compiler] Compiled new assembly "+
// "for {0}", asset);
// Because windows likes to perform exclusive locks, we simply

View File

@@ -265,7 +265,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
}
catch (Exception e)
{
m_Engine.Log.ErrorFormat("[Script] Error loading assembly {0}\n"+e.ToString(), assembly);
m_log.ErrorFormat("[Script] Error loading assembly {0}\n"+e.ToString(), assembly);
}
try
@@ -275,14 +275,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_Script.InitApi(kv.Key, kv.Value);
}
// m_Engine.Log.Debug("[Script] Script instance created");
// m_log.Debug("[Script] Script instance created");
part.SetScriptEvents(m_ItemID,
(int)m_Script.GetStateEventFlags(State));
}
catch (Exception e)
{
m_Engine.Log.Error("[Script] Error loading script instance\n"+e.ToString());
m_log.Error("[Script] Error loading script instance\n"+e.ToString());
return;
}
@@ -317,7 +317,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_LocalID, m_ItemID, m_ObjectID,
PluginData);
// m_Engine.Log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", m_PrimName, m_ScriptName);
// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", m_PrimName, m_ScriptName);
part.SetScriptEvents(m_ItemID,
(int)m_Script.GetStateEventFlags(State));
@@ -344,12 +344,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
}
else
{
m_Engine.Log.Error("[Script] Unable to load script state: Memory limit exceeded");
m_log.Error("[Script] Unable to load script state: Memory limit exceeded");
}
}
catch (Exception e)
{
m_Engine.Log.ErrorFormat("[Script] Unable to load script state from xml: {0}\n"+e.ToString(), xml);
m_log.ErrorFormat("[Script] Unable to load script state from xml: {0}\n"+e.ToString(), xml);
}
}
else
@@ -359,7 +359,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (presence != null && (!postOnRez))
presence.ControllingClient.SendAgentAlertMessage("Compile successful", false);
// m_Engine.Log.ErrorFormat("[Script] Unable to load script state, file not found");
// m_log.ErrorFormat("[Script] Unable to load script state, file not found");
}
}
@@ -378,7 +378,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (m_stateSource == StateSource.NewRez)
{
// m_Engine.Log.Debug("[Script] Posted changed(CHANGED_REGION_RESTART) to script");
// m_log.Debug("[Script] Posted changed(CHANGED_REGION_RESTART) to script");
PostEvent(new EventParams("changed",
new Object[] {new LSL_Types.LSLInteger(256)}, new DetectParams[0]));
}
@@ -473,7 +473,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (m_CurrentResult == null)
m_CurrentResult = m_Engine.QueueEventHandler(this);
else
m_Engine.Log.Error("[Script] Tried to start a script that was already queued");
m_log.Error("[Script] Tried to start a script that was already queued");
}
}
}
@@ -545,7 +545,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void PostEvent(EventParams data)
{
// m_Engine.Log.DebugFormat("[Script] Posted event {2} in state {3} to {0}.{1}",
// m_log.DebugFormat("[Script] Posted event {2} in state {3} to {0}.{1}",
// m_PrimName, m_ScriptName, data.EventName, m_State);
if (!Running)
@@ -659,7 +659,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (data.EventName == "state") // Hardcoded state change
{
// m_Engine.Log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
// m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
// m_PrimName, m_ScriptName, data.Params[0].ToString());
m_State=data.Params[0].ToString();
AsyncCommandManager.RemoveScript(m_Engine,
@@ -680,7 +680,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
m_LocalID);
// m_Engine.Log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
// m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
// m_PrimName, m_ScriptName, data.EventName, m_State);
try
@@ -726,12 +726,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
}
catch (Exception e2) // LEGIT: User Scripting
{
m_Engine.Log.Error("[Script]: "+
"Error displaying error in-world: " +
e2.ToString());
m_Engine.Log.Error("[Script]: " +
"Errormessage: Error compiling script:\r\n" +
e.ToString());
m_log.Error("[Script]: "+
"Error displaying error in-world: " +
e2.ToString());
m_log.Error("[Script]: " +
"Errormessage: Error compiling script:\r\n" +
e.ToString());
}
}
else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))