我使用的是log4cplus库(v1.0.0),记录器设置如下:
std::string formatString("%-5p [%F,%L] %m%n");
std::auto_ptr <log4cplus::Layout> layout(new log4cplus::PatternLayout(formatString));
logAppender->setLayout(layout);我使用以下函数进行日志记录:
log4cplus::Logger logger;
logger.log(INFO_LOG_LEVEL, msg);日志中打印的日志消息为:
DEBUG [,] My log message
INFO [,] My other log message它不打印日志中的文件名或行号。我遗漏了什么?
发布于 2013-03-13 23:31:52
这是因为您没有将任何信息传递给log()函数。log()函数声明如下:
void log(LogLevel ll, const log4cplus::tstring& message,
const char* file=NULL, int line=-1) const;正如您所看到的,除非您提供文件和行信息,否则它会传入“空”值。
您可以自己传递信息,也可以包含log4cplus/loggingmacros.h并使用提供的日志记录宏,这些宏将为您完成此操作。
https://stackoverflow.com/questions/15388923
复制相似问题