Convert pCampBot to use log4net

ThreadPoolClientBranch
Jeff Ames 2008-02-07 04:53:42 +00:00
parent 49622dfbc5
commit 87e2dd7c80
5 changed files with 50 additions and 55 deletions

28
bin/pCampBot.exe.config Normal file
View File

@ -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>

View File

@ -44,25 +44,24 @@ namespace pCampBot
/// </summary> /// </summary>
public class BotManager : conscmd_callback 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 List<PhysicsBot> m_lBot;
protected Thread[] m_td; protected Thread[] m_td;
protected string m_logFilename = "botlog.log";
protected bool m_verbose = true; protected bool m_verbose = true;
protected Random somthing = new Random(System.Environment.TickCount); protected Random somthing = new Random(System.Environment.TickCount);
protected int numbots = 0; protected int numbots = 0;
protected IConfig Previous_config; protected IConfig Previous_config;
/// <summary> /// <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> /// </summary>
public BotManager() public BotManager()
{ {
m_console = CreateConsole();
m_log = CreateLog(); MainConsole.Instance = m_console;
MainLog.Instance = m_log;
m_lBot = new List<PhysicsBot>(); m_lBot = new List<PhysicsBot>();
} }
/// <summary> /// <summary>
@ -101,7 +100,6 @@ namespace pCampBot
{ {
startupBot(i, Previous_config); startupBot(i, Previous_config);
} }
} }
/// <summary> /// <summary>
@ -151,19 +149,19 @@ namespace pCampBot
switch (eventt) switch (eventt)
{ {
case EventType.CONNECTED: case EventType.CONNECTED:
MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Connected"); m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Connected");
numbots++; numbots++;
break; break;
case EventType.DISCONNECTED: 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(); m_td[m_lBot.IndexOf(callbot)].Abort();
numbots--; numbots--;
if (numbots >1) if (numbots >1)
Environment.Exit(0); Environment.Exit(0);
break; break;
} }
} }
/// <summary> /// <summary>
/// Shutting down all bots /// Shutting down all bots
/// </summary> /// </summary>
@ -173,23 +171,15 @@ namespace pCampBot
{ {
pb.shutdown(); pb.shutdown();
} }
} }
/// <summary> /// <summary>
/// Standard Creatlog routine /// Standard CreateConsole routine
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
protected LogBase CreateLog() protected ConsoleBase CreateConsole()
{ {
if (!Directory.Exists(Util.logDir())) return new ConsoleBase("Region", this);
{
Directory.CreateDirectory(Util.logDir());
}
return new LogBase((Path.Combine(Util.logDir(), m_logFilename)), "Region", this, m_verbose);
} }
/// <summary> /// <summary>
@ -219,11 +209,11 @@ namespace pCampBot
switch (command) switch (command)
{ {
case "shutdown": case "shutdown":
MainLog.Instance.Warn("BOTMANAGER", "Shutting down bots"); m_console.Warn("BOTMANAGER", "Shutting down bots");
doBotShutdown(); doBotShutdown();
break; break;
case "quit": 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); Environment.Exit(0);
break; break;
case "addbots": case "addbots":
@ -234,10 +224,8 @@ namespace pCampBot
addbots(newbots); addbots(newbots);
break; break;
case "help": 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; break;
} }
} }
@ -250,5 +238,4 @@ namespace pCampBot
} }
} }
} }

View File

@ -38,8 +38,6 @@ using OpenSim.Framework;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using Timer=System.Timers.Timer; using Timer=System.Timers.Timer;
namespace pCampBot namespace pCampBot
{ {
public class PhysicsBot public class PhysicsBot
@ -122,12 +120,12 @@ namespace pCampBot
{ {
client.Network.Logout(); client.Network.Logout();
} }
/// <summary> /// <summary>
/// This is the bot startup loop. /// This is the bot startup loop.
/// </summary> /// </summary>
public void startup() public void startup()
{ {
client.Settings.LOGIN_SERVER = loginURI; client.Settings.LOGIN_SERVER = loginURI;
client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected); client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected);
client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected); client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected);
@ -147,14 +145,12 @@ namespace pCampBot
} }
else else
{ {
MainConsole.Instance.Error(firstname + " " + lastname, "Can't login: " + client.Network.LoginMessage);
MainLog.Instance.Error(firstname + " " + lastname,"Can't Log in: " + client.Network.LoginMessage);
if (OnDisconnected != null) if (OnDisconnected != null)
{ {
OnDisconnected(this, EventType.DISCONNECTED); OnDisconnected(this, EventType.DISCONNECTED);
} }
} }
} }
public void Network_OnConnected(object sender) public void Network_OnConnected(object sender)
@ -163,12 +159,10 @@ namespace pCampBot
{ {
OnConnected(this, EventType.CONNECTED); OnConnected(this, EventType.CONNECTED);
} }
} }
public void Simulator_Connected(object sender) public void Simulator_Connected(object sender)
{ {
} }
public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message) public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
@ -177,17 +171,12 @@ namespace pCampBot
{ {
OnDisconnected(this,EventType.DISCONNECTED); OnDisconnected(this,EventType.DISCONNECTED);
} }
} }
public string[] readexcuses() public string[] readexcuses()
{ {
string allexcuses = ""; string allexcuses = "";
string file = Path.Combine(Util.configDir(), "excuses"); string file = Path.Combine(Util.configDir(), "excuses");
if (File.Exists(file)) if (File.Exists(file))
{ {
@ -196,13 +185,7 @@ namespace pCampBot
csr.Close(); csr.Close();
} }
return allexcuses.Split(Environment.NewLine.ToCharArray()); return allexcuses.Split(Environment.NewLine.ToCharArray());
} }
} }
} }

View File

@ -35,7 +35,6 @@ using Nini.Config;
using System.Threading; using System.Threading;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
namespace pCampBot namespace pCampBot
{ {
/// <summary> /// <summary>
@ -47,10 +46,9 @@ namespace pCampBot
CONNECTED = 1, CONNECTED = 1,
DISCONNECTED = 2 DISCONNECTED = 2
} }
public class pCampBot public class pCampBot
{ {
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
@ -63,7 +61,6 @@ namespace pCampBot
cs.AddSwitch("Startup", "lastname"); cs.AddSwitch("Startup", "lastname");
cs.AddSwitch("Startup", "password"); cs.AddSwitch("Startup", "password");
IConfig ol = cs.Configs["Startup"]; IConfig ol = cs.Configs["Startup"];
int botcount = ol.GetInt("botcount", 1); int botcount = ol.GetInt("botcount", 1);
BotManager bm = new BotManager(); BotManager bm = new BotManager();
@ -72,9 +69,8 @@ namespace pCampBot
bm.dobotStartup(botcount, ol); bm.dobotStartup(botcount, ol);
while (true) while (true)
{ {
MainLog.Instance.MainLogPrompt(); MainConsole.Instance.Prompt();
} }
} }
} }
} }

View File

@ -52,6 +52,7 @@
<Reference name="OpenSim.Framework.dll"/> <Reference name="OpenSim.Framework.dll"/>
<Reference name="OpenSim.Framework.Console.dll"/> <Reference name="OpenSim.Framework.Console.dll"/>
<Reference name="Nini.dll" /> <Reference name="Nini.dll" />
<Reference name="log4net"/>
<Files> <Files>
<Match pattern="*.cs" recurse="true"/> <Match pattern="*.cs" recurse="true"/>