Valhalla Legends Forums Archive | General Programming | Useful Data Logging

AuthorMessageTime
Myndfyr
One of the things I'm trying to do with the next bot is to allow the user to opt-in to submit data to me that would allow me to improve the API, or to specify what level of debugging to have.  So at strategic locations I have code like this:

[code]
protected virtual void ParseChatEvent(ChatEventId id, int flags, int ping, string username, string text)
{
#if !OPTIMIZED
if (Globals.DebuggingLevel >= DebugLevelFlags.HelpApiDevelopment)
{
// TO DO
//
// Log data.
}
#endif



protected virtual bool ParseBNCS(BncsPackets id, int len, byte[] data)
{
bool processed = false;
IncomingPacketStream str = new IncomingPacketStream(data);
str.Seek(4);

#if !OPTIMIZED
if (Globals.DebuggingLevel >= DebugLevelFlags.HelpApiDevelopment)
{
// TO DO
//
// Log data.
}
#endif



protected virtual void OnBnlsDataReceived(byte[] dataBuffer)
{
EventHost.OnPacketTransmitted(true, dataBuffer, Settings.HashingServer.IPAddress,
Settings.HashingServer.Port);

#if !OPTIMIZED
if (Globals.DebuggingLevel >= DebugLevelFlags.CompleteLogs)
{
// TO DO
//
// Log this transmission.
}
#endif



if (Globals.DebuggingLevel >= DebugLevelFlags.ConnectionErrors)
{
// TO DO
//
// Log this error.
}
[/code]

What I'm looking for in the first and second examples are, for instance, the most frequently-processed chat event or BNCS packet so that I can bump that case up to the top (for less jump checks).  The third is to log a packet dump, and the fourth is to simply log an error condition with locals and that.

I have something similar set up already in my event dispatcher class: I was fortunately able to generalize it.  I plan on writing out the type and position of each argument.  Right now it's just a stub:
[code]
protected virtual void LogError(EventType type, Priority handlerPriority, Exception error, object[] arguments)
{
// what to do here?
}
[/code]

Unfortunately, I can't just display an error to the user because the application is intended to run as a Service.  And for "API Development Help", I don't want to record text data, because I would prefer that I can write a simple helper app to parse our data and give us the results.  I'm torn about packet logs; I could see a case for either binary or text.

Are there any particular formats you all have found to be particularly helpful or useful in these kinds of situations?
December 25, 2004, 8:44 AM
Kp
Text mode logs can be ok, as long as you're careful that what is written can be unambiguously described in a context-free way.  The BNCS chatgate talk event is an example of this, although a bit of care is required since they don't escape embedded doublequotes (but do use dquotes to start/stop the message text).  Regardless of whether you pick text or binary logs, I'd suggest embedding some sort of 'log version' header on it so that you can change versions later and tell your parser explicitly what it's reading, rather than adding extra data later to advise the parser this is a "new style" log.
December 25, 2004, 5:41 PM
Arta
..and for optimising your switch, SID_PING, SID_DISPLAYAD and SID_CHATEVENT are good candidates for messages. For chat events, it really depends what kind of channel you're in. In a busy public channel you'd probably want to do EID_TALK, whereas in a quite private channel you might be better off doing EID_JOIN/EID_LEAVE or perhaps even EID_USERFLAGS if your client squelches itsself to look for invisible users.
December 26, 2004, 9:20 AM
kamakazie
I think this may a be a little off-topic but could help you.  Try looking at the Trace object.  I know it exists in the 2.0 framework don't know about lower versions.  But it's an extremely nice class that will allow you to redirect output to the console, file, event log, xml serializer, binary serializer or even a custom listener.  You can even has multiple listeners.
December 27, 2004, 10:11 PM

Search