MEONMedical / Log4Qt

Log4Qt - Logging for the Qt cross-platform application framework
Apache License 2.0
589 stars 235 forks source link

log4Qt cannot output source file names, line numbers, function names, etc. #42

Closed libaineu2004 closed 4 years ago

libaineu2004 commented 4 years ago

log4Qt cannot output source file names, line numbers, function names, etc.

log4Qt version:1.5.1 My program:main.cpp

include

include

include

include <log4qt/consoleappender.h>

include <log4qt/logger.h>

include <log4qt/loggerrepository.h>

include <log4qt/patternlayout.h>

int main(int argc, char *argv[]) { QCoreApplication a(argc, argv);

Log4Qt::Logger *logger = Log4Qt::Logger::rootLogger();
Log4Qt::PatternLayout *layout = new Log4Qt::PatternLayout();
layout->setHeader("----- start -----");
layout->setFooter("----- end -----");
layout->setConversionPattern("%d{yyyy-MM-dd hh:mm:ss} [%p] %c{2} %M.%L %x - %m%n");
layout->activateOptions();

// ConsoleAppender
Log4Qt::ConsoleAppender *appender = new Log4Qt::ConsoleAppender(layout, 
Log4Qt::ConsoleAppender::STDOUT_TARGET);
appender->activateOptions();
logger->addAppender(appender);

logger->setLevel(Log4Qt::Level::DEBUG_INT);
logger->debug("Debug, Log4Qt!");
logger->info("Info, Log4Qt!");

//shutdown logger->removeAllAppenders(); logger->loggerRepository()->shutdown();

return a.exec();

}

The results are as follows: ----- start ----- 2020-03-24 21:08:14 [DEBUG] root .-1 - Debug, Log4Qt! 2020-03-24 21:08:14 [INFO] root .-1 - Info, Log4Qt! ----- end -----

I used "%M.%L", but log4Qt cannot output source file names, line numbers, function names, etc. why?

andibacher commented 4 years ago

Look at #37 I think there is described why it does not work.

libaineu2004 commented 4 years ago

Look at #37 I think there is described why it does not work.

ok