[crossfire] code cleanup commit.
Tchize
tchize at myrealbox.com
Tue Jun 6 04:18:21 CDT 2006
Sorry, jumping in Thread a bit late.
I have quite a few experience with logging mecanism, here is my suggestion
Arrange log entries in a hierarchy (scopes) like is done in java logging
mecanisms:
example:
common.object (for everything related to object)
Provide different levels of logging
(idea: finest, fine, info, warning, error, critical), default visible
level would be info
Then you can say in config (or command line)
default=warning
common.object=finest
server.monster=finest
server=info
random_maps=info
socket=info
Provide with the possibility to check if a specific level is enabled
if (loglevel_enabled(scope,LOG_FINEST)){
/* do very complex operations here that can not be easily resumed in
a function call */
/* optionally at end issue a log call */
LOG(scope,LOG_FINEST,result_of_complex_logging_operations)
}
Use also as information the line,file,function information, as
preprocessor provide them , but do not use them for filtering, use them
only when analysing a log to know where a problem occurs
Cherry on the cake: provide ASSERT statements derived from logging
mecanism that could issue warning/error if assertions fails
This way, log call are only made when necessary and are very fast if not
activated.
There are two critical points if we want usefull debugs,
- performance loss when logging is not usefull should be minimal (no
unneeded operation)
- should be able to enable / disable by whole tree or by single
elements depending on what you need
I think the idea of bitmask to tell a log call is part of several
section at same time is useless. A log call should always be localized
easily to activate / deactivate in config.
Note i have used the above described mecanism in java for 1 year, this
is very flexible, powerfull and suffer no noticeable performance loss
while there are tons of log messages.
I suggest you take a look at how log4j works. Also, i checked log4c, but
unfortunately, it use gcc specific features (like __attributes__)
More information about the crossfire
mailing list