logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Butcher <p...@paulbutcher.com>
Subject Bug with statically initialised loggers?
Date Wed, 08 Jun 2005 21:36:03 GMT
I believe that I have uncovered a bug with statically initialised loggers. It 
is my belief that it should be possible to initialise loggers in any order, 
statically or otherwise, and the inheritance hierarchy should "just work"? I 
believe that I have found an example where this is not the case. I am using 
g++ (GCC) 3.3.4 (pre 3.3.5 20040809) running on SUSE Linux 9.2.

Please forgive the length of this mail, but this is the simplest example I 
have been able to create which reproduces the problem. Everything works fine, 
for example, if I place everything in a single source file.

Given the following three source files:

logtest.cpp --------------------------------------------------------
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>

using namespace log4cxx;

static LoggerPtr logger = Logger::getLogger("logtest");

void test1();
void test2();

int main()
{
  PropertyConfigurator::configure(File("log4j.configuration"));

  LOG4CXX_DEBUG(logger, "test");

  test1();
  test2();

  return 0;
}
--------------------------------------------------------

test1.cpp --------------------------------------------------------
#include <log4cxx/logger.h>

using namespace log4cxx;

static LoggerPtr logger = Logger::getLogger("logtest.test1");

void test1()
{
  LOG4CXX_DEBUG(logger, "test");
}
--------------------------------------------------------

test2.cpp --------------------------------------------------------
#include <log4cxx/logger.h>

using namespace log4cxx;

static LoggerPtr logger = Logger::getLogger("logtest.test2");

void test2()
{
  LOG4CXX_DEBUG(logger, "test");
}
--------------------------------------------------------

With the following log4j.configuration:

--------------------------------------------------------
log4j.rootLogger=DEBUG, A

log4j.appender.A=org.apache.ConsoleAppender
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-5p %c - %m %n
--------------------------------------------------------

I get the following output:

--------------------------------------------------------
DEBUG logtest - test
DEBUG logtest.test1 - test
DEBUG logtest.test2 - test
--------------------------------------------------------

Which I believe is correct. With the following log4j.configuration, however:

--------------------------------------------------------
log4j.rootLogger=DEBUG, A
log4j.logger.logtest=INFO

log4j.appender.A=org.apache.ConsoleAppender
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-5p %c - %m %n
--------------------------------------------------------

I get the following output:

--------------------------------------------------------
DEBUG logtest.test1 - test
--------------------------------------------------------

Which I do not believe to be correct.

Have I understood this correctly?

paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

Mime
View raw message