0

My Debugging Library

This is kinda evolving, but finding it a really useful thing to have. I hope eventually I can put this in one script and all my stuff can access it.

 [Flags]
public enum DebugLevel
{
None = 0,
Info = 1,
Debug = 2,
Warning = 4,
Error = 8
}

private void DebugMsg(string message)
{
DebugInfoMsg(message);
}

private void DebugInfoMsg(string message)
{
if (!Debug)
return;

if(!DebugLvl.HasFlag(DebugLevel.Info))
return;

if (DebugTo.Equals("All") == true)
MessageAllUsers(message, DebugLevel.Info);
else
MessageOwner(message, DebugLevel.Info);
}

private void DebugDebugMsg(string message)
{
if (!Debug)
return;

if (!DebugLvl.HasFlag(DebugLevel.Debug))
return;

if (DebugTo.Equals("All") == true)
MessageAllUsers("Debug: " + message, DebugLevel.Info);
else
MessageOwner("Debug: " + message, DebugLevel.Info);
}

private void DebugWarnMsg(string message)
{
if (!Debug)
return;

if (!DebugLvl.HasFlag(DebugLevel.Warning))
return;

if (DebugTo.Equals("All") == true)
MessageAllUsers("Warning: " + message, DebugLevel.Warning);
else
MessageOwner("Warning: " + message, DebugLevel.Warning);
}

private void DebugErrorMsg(string message)
{
if (!Debug)
return;

if (!DebugLvl.HasFlag(DebugLevel.Error))
return;

if (DebugTo.Equals("All") == true)
MessageAllUsers("Error: " + message, DebugLevel.Error);
else
MessageOwner("Error: " + message, DebugLevel.Error);
}

private void MessageAllUsers(string message, DebugLevel level = DebugLevel.Info)
{
foreach (var Agent in ScenePrivate.GetAgents())
{
try
{
Agent.SendChat(message);
}
catch (Exception) { } // assume Agent left the scene
}
}

private void MessageOwner(string message, DebugLevel level = DebugLevel.Info)
{
foreach (var Agent in ScenePrivate.GetAgents())
{
try
{
if (!string.Equals(Agent.AgentInfo.Name, OwnerName, StringComparison.CurrentCultureIgnoreCase))
continue;

Agent.SendChat(message);
}
catch (Exception) { } // assume Agent left the scene
}
}
}


private string OwnerName = "Gindipple";
private bool Debug = true;
private DebugLevel DebugLvl = DebugLevel.Warning | DebugLevel.Error | DebugLevel.Info;
private string DebugTo = "All";


Obviously you'll want to tweak some if you use it, like OwnerName

I left off "Info: " in the info message, I didn't want that one to be overly cluttered as I kinda use it to relay out messages in general to users

 

 

0 comments

Please sign in to leave a comment.