The typical pattern is to use a static logger member in a class which
results in getLogger() being called once per class during
initialization:
foo.h
class Foo {
statlc log4cxx::LoggerPtr logger;
void hello();
};
foo.cpp
log4cxx::LoggerPtr Foo::logger(Logger::getLogger("foo"));
void Foo::hello() {
LOG4CXX_INFO(logger, "Hello");
}
Did you have a compelling reason to make repeated calls to getLogger()?
If your caching improved performance, there must be some potential for
optimization to getLogger() which should be doing roughly the same
thing internally. Frequent calls to getLogger() is an atypical usage
pattern, so it hasn't been benchmarked.
On Aug 18, 2009, at 3:19 PM, david.we...@l-3com.com wrote:
All,
I was recently working on a project which was very time sensitive.
Milliseconds were prescious, and we had great interest in using
LOG4CXX, only in debugging problems (where time wasn't nearly as
critical).
On the web site, I saw that getLogger("asdf") will return the same
object as a subsequent call to getLogger("asdf"). When we created
multiple objects of the same type, each of which had a logger
instance with the same name, we profiled the code, and found that
eacy getLogger() call was taking quite a lot of time. Unfortunately
the numbers are lost, but it was something like 100 us or ms. These
numbers are a world apart, but when it came to creating ~1000 of my
own objects, the amount of time spent creating those loggers became
unacceptable.
We ultimately found that by creating a caching mechanism using a
"loggerName" -> "loggerObject" map, made the subsequent calls much
more manageable.
I was just wondering if anyone else has seen this sort of behavior.
--dw