问题描述
|
我正在使用log4cxx写入日志。
这是我的日志记录配置,在这里,我的日志文件大小为4 MB。
之后,它将自我重写。我能够使用以下配置文件和c ++代码进行登录。
现在,我想阅读属性和相关值
示例:我想读取程序中出于某些目的所需的文件大小信息。
**CONfig FILE**
log4j.rootLogger=debug,stdout,R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller\'s file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
log4j.appender.R.MaxFileSize=4MB
# Keep one backup file log4j.appender.R.MinBackupIndex = -1
log4j.appender.R.MaxBackupIndex = 0
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
**C++ code**
int main()
{
LoggerPtr logger(Logger::getLogger(\"Gateway\"));
log4cxx::helpers::Pool pool;
log4cxx::File file(\"example.log\");
PropertyConfigurator::configure(\"log4j.properties\");
LOG4CXX_INFO(logger,ctime( &rawtime )<<\"\\t\"<<pMessage->GetMessageHeader()->GetGatewayMAC()<<\"\\t\"<<strCommandType<<\"\\t\"<<chBuffer<<\"\\t\"<<\"OUT\"<<\"\\t\"<<pPacket<<\"\\n\");
}
我如何读取配置文件信息。
解决方法
也许可以使用log4cxx :: helpers :: Properties中的getProperty方法来工作。
http://logging.apache.org/log4cxx/apidocs/classlog4cxx_1_1helpers_1_1_properties.html