Convert pCampBot to use log4net
parent
49622dfbc5
commit
87e2dd7c80
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
|
||||
</configSections>
|
||||
<appSettings>
|
||||
</appSettings>
|
||||
<log4net>
|
||||
<appender name="Console" type="OpenSim.Framework.Console.OpenSimAppender, OpenSim.Framework.Console">
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date{HH:mm:ss} - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
|
||||
<file value="pCampBot.log" />
|
||||
<appendToFile value="false" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %-5level - %logger %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<root>
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="Console" />
|
||||
<appender-ref ref="LogFileAppender" />
|
||||
</root>
|
||||
</log4net>
|
||||
</configuration>
|
|
@ -44,25 +44,24 @@ namespace pCampBot
|
|||
/// </summary>
|
||||
public class BotManager : conscmd_callback
|
||||
{
|
||||
protected LogBase m_log;
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
protected ConsoleBase m_console;
|
||||
protected List<PhysicsBot> m_lBot;
|
||||
protected Thread[] m_td;
|
||||
protected string m_logFilename = "botlog.log";
|
||||
protected bool m_verbose = true;
|
||||
protected Random somthing = new Random(System.Environment.TickCount);
|
||||
protected int numbots = 0;
|
||||
protected IConfig Previous_config;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor Creates Mainlog.Instance to take commands and provide the place to write data
|
||||
/// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
|
||||
/// </summary>
|
||||
public BotManager()
|
||||
{
|
||||
|
||||
m_log = CreateLog();
|
||||
MainLog.Instance = m_log;
|
||||
m_console = CreateConsole();
|
||||
MainConsole.Instance = m_console;
|
||||
m_lBot = new List<PhysicsBot>();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -101,7 +100,6 @@ namespace pCampBot
|
|||
{
|
||||
startupBot(i, Previous_config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -151,19 +149,19 @@ namespace pCampBot
|
|||
switch (eventt)
|
||||
{
|
||||
case EventType.CONNECTED:
|
||||
MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Connected");
|
||||
m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Connected");
|
||||
numbots++;
|
||||
break;
|
||||
case EventType.DISCONNECTED:
|
||||
MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Disconnected");
|
||||
m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Disconnected");
|
||||
m_td[m_lBot.IndexOf(callbot)].Abort();
|
||||
numbots--;
|
||||
if (numbots >1)
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shutting down all bots
|
||||
/// </summary>
|
||||
|
@ -173,23 +171,15 @@ namespace pCampBot
|
|||
{
|
||||
pb.shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Standard Creatlog routine
|
||||
/// Standard CreateConsole routine
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected LogBase CreateLog()
|
||||
protected ConsoleBase CreateConsole()
|
||||
{
|
||||
if (!Directory.Exists(Util.logDir()))
|
||||
{
|
||||
Directory.CreateDirectory(Util.logDir());
|
||||
}
|
||||
|
||||
return new LogBase((Path.Combine(Util.logDir(), m_logFilename)), "Region", this, m_verbose);
|
||||
return new ConsoleBase("Region", this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -219,11 +209,11 @@ namespace pCampBot
|
|||
switch (command)
|
||||
{
|
||||
case "shutdown":
|
||||
MainLog.Instance.Warn("BOTMANAGER", "Shutting down bots");
|
||||
m_console.Warn("BOTMANAGER", "Shutting down bots");
|
||||
doBotShutdown();
|
||||
break;
|
||||
case "quit":
|
||||
MainLog.Instance.Warn("DANGER", "This should only be used to quit the program if you've already used the shutdown command and the program hasn't quit");
|
||||
m_console.Warn("DANGER", "This should only be used to quit the program if you've already used the shutdown command and the program hasn't quit");
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
case "addbots":
|
||||
|
@ -234,10 +224,8 @@ namespace pCampBot
|
|||
addbots(newbots);
|
||||
break;
|
||||
case "help":
|
||||
MainLog.Instance.Notice("HELP", "\nshutdown - graceful shutdown\naddbots <n> - adds n bots to the test\nquit - forcequits, dangerous if you have not already run shutdown");
|
||||
m_console.Notice("HELP", "\nshutdown - graceful shutdown\naddbots <n> - adds n bots to the test\nquit - forcequits, dangerous if you have not already run shutdown");
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,5 +238,4 @@ namespace pCampBot
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ using OpenSim.Framework;
|
|||
using OpenSim.Framework.Console;
|
||||
using Timer=System.Timers.Timer;
|
||||
|
||||
|
||||
|
||||
namespace pCampBot
|
||||
{
|
||||
public class PhysicsBot
|
||||
|
@ -122,12 +120,12 @@ namespace pCampBot
|
|||
{
|
||||
client.Network.Logout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is the bot startup loop.
|
||||
/// </summary>
|
||||
public void startup()
|
||||
{
|
||||
|
||||
client.Settings.LOGIN_SERVER = loginURI;
|
||||
client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected);
|
||||
client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected);
|
||||
|
@ -147,14 +145,12 @@ namespace pCampBot
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
MainLog.Instance.Error(firstname + " " + lastname,"Can't Log in: " + client.Network.LoginMessage);
|
||||
MainConsole.Instance.Error(firstname + " " + lastname, "Can't login: " + client.Network.LoginMessage);
|
||||
if (OnDisconnected != null)
|
||||
{
|
||||
OnDisconnected(this, EventType.DISCONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Network_OnConnected(object sender)
|
||||
|
@ -163,12 +159,10 @@ namespace pCampBot
|
|||
{
|
||||
OnConnected(this, EventType.CONNECTED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Simulator_Connected(object sender)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
|
||||
|
@ -177,16 +171,11 @@ namespace pCampBot
|
|||
{
|
||||
OnDisconnected(this,EventType.DISCONNECTED);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public string[] readexcuses()
|
||||
{
|
||||
|
||||
|
||||
|
||||
string allexcuses = "";
|
||||
|
||||
|
||||
string file = Path.Combine(Util.configDir(), "excuses");
|
||||
if (File.Exists(file))
|
||||
|
@ -195,14 +184,8 @@ namespace pCampBot
|
|||
allexcuses = csr.ReadToEnd();
|
||||
csr.Close();
|
||||
}
|
||||
|
||||
|
||||
return allexcuses.Split(Environment.NewLine.ToCharArray());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ using Nini.Config;
|
|||
using System.Threading;
|
||||
using OpenSim.Framework.Console;
|
||||
|
||||
|
||||
namespace pCampBot
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -47,10 +46,9 @@ namespace pCampBot
|
|||
CONNECTED = 1,
|
||||
DISCONNECTED = 2
|
||||
}
|
||||
|
||||
public class pCampBot
|
||||
{
|
||||
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
@ -63,7 +61,6 @@ namespace pCampBot
|
|||
cs.AddSwitch("Startup", "lastname");
|
||||
cs.AddSwitch("Startup", "password");
|
||||
|
||||
|
||||
IConfig ol = cs.Configs["Startup"];
|
||||
int botcount = ol.GetInt("botcount", 1);
|
||||
BotManager bm = new BotManager();
|
||||
|
@ -72,9 +69,8 @@ namespace pCampBot
|
|||
bm.dobotStartup(botcount, ol);
|
||||
while (true)
|
||||
{
|
||||
MainLog.Instance.MainLogPrompt();
|
||||
MainConsole.Instance.Prompt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
<Reference name="OpenSim.Framework.dll"/>
|
||||
<Reference name="OpenSim.Framework.Console.dll"/>
|
||||
<Reference name="Nini.dll" />
|
||||
<Reference name="log4net"/>
|
||||
|
||||
<Files>
|
||||
<Match pattern="*.cs" recurse="true"/>
|
||||
|
|
Loading…
Reference in New Issue