[Box Backup-dev] Logging
Martin Ebourne
boxbackup-dev at fluffy.co.uk
Sun Dec 25 20:39:34 GMT 2005
There seems to have been a huge amount of discussion on here about
logging. I'm not replying to any specific message because they all have
points.
I'm pretty sure we can come up with something that satisfies everyone's
requirements, although it will include iostream using <<. ;)
Here's an example line from one of my projects. It's using log4cxx, but
we can do something just the same, and since we only want a small
subset of the functionality, it shouldn't be hard.
LOG4CXX_DEBUG(s_log, "Incoming event: " << time << ", " << sourceType
<< ", " << sourceName << ", " << payload);
This is a macro, so it can be defined to NULL and therefore have zero
impact in release builds.
It could expand to many things, but one possibility would be:
#define BOX_DEBUG(logger, stuff) \
do { \
std::ostringstream line; \
line << stuff; \
logger.write(BOX_DEBUG_LEVEL, __FUNCTION__, __LINE__, line.str());
} while(0)
Another would be:
#define BOX_DEBUG(logger, stuff) \
do { \
logger.stream(BOX_DEBUG_LEVEL) << stuff; \
} while(0)
For maximum performance while still being able to disable certain
levels at run time this would do:
#define BOX_DEBUG(logger, stuff) \
do { \
if(logger.active(BOX_DEBUG_LEVEL)) \
{ \
std::ostringstream line; \
line << stuff; \
logger.write(BOX_DEBUG_LEVEL, __FUNCTION__, __LINE__, line.str());
} \
} while(0)
Then separate macros for each of BOX_INFO, BOX_ERROR, BOX_FATAL.
Only the debug one has to compile out, and even that can be made
conditional with configure.ac. We loose the TRACEn where the n really
isn't nice at all.
As to the objects and over engineering. Really we only need a few small
classes with a couple of virtual methods in each. There's no need to
make this hugely complicated.
Cheers,
Martin.
More information about the Boxbackup-dev
mailing list