Tuesday, June 26, 2012

log4cxx insights

i really liked log4cxx and while i did a thorough research, turned out there were a few things i hadn't realised log4cxx featured or was capable of

- hierarchy is awesome, i had used it with test cases like
log4j.logger.main=ERROR, console, file
log4j.logger.main.another=INFO

where`another` inherits console and file appenders from `main`

but i hadn't realised that if `another` featured, well, another console appender, then the log message would be displayed twice - once for the console appender from `main` and once from `another`

log4j.logger.main.another=INFO, console2

the way to avoid this is to tell log4cxx we don't want the child to inherit any appenders from the parent, like this -
log4j.additivity.main.another=false

it is actually quite evident from the quick tutorial on the log4cxx site, but i guess i kindda missed that


- different log levels for each appender - now i  really hadn't realised that log4cxx was capable of this: when you want console to print all messages, but file output would feature only errors
turns out this can be easilly done with

log4j.appender.console.Threshold=TRACE
log4j.appender.file.Threshold=ERROR

isn't this beautiful!!


there hasn't been official release for log4cxx for quite a few years which might be startling, but then this library is so awesome, i'd rather risk and use it in production then go for another one, or (no way) write a custom framework...