• Welcome to Valhalla Legends Archive.
 

Useful Data Logging

Started by MyndFyre, December 25, 2004, 02:44 AM

Previous topic - Next topic

MyndFyre

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:


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.
}


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:

protected virtual void LogError(EventType type, Priority handlerPriority, Exception error, object[] arguments)
{
// what to do here?
}


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?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

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.

dxoigmn

#3
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.