Question

I am using the log4cplus library (v1.0.0) and the logger set up is as follows:

std::string formatString("%-5p [%F,%L] %m%n");
std::auto_ptr <log4cplus::Layout> layout(new log4cplus::PatternLayout(formatString));
logAppender->setLayout(layout);

I am using the following function to log:

log4cplus::Logger logger;
logger.log(INFO_LOG_LEVEL, msg);

The log message printed in the log is:

DEBUG [,] My log message
INFO  [,] My other log message

It does not print the file name or the line number in the log. What am I missing?

Was it helpful?

Solution

This is because you are not passing any of the information into the log() function. The log() function is declared as follows:

void log(LogLevel ll, const log4cplus::tstring& message,
         const char* file=NULL, int line=-1) const;

As you can see, unless you provide the file and line information, it passes in "empty" values.

Either you pass the information down yourself or you include log4cplus/loggingmacros.h and use provided logging macros, which do that for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top