读取 Log4cxx 中的属性信息
我正在使用 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");
}
我如何读取配置文件信息??
I am using log4cxx for writing to the log.
This is my configuration for logging, Here i have log file size of of 4 MB.
after that it will rewrite it self.I am able to log using following config file and c++ code.
Now I wanted to read the properties and the associated value
example : I wanted to read file size info which is required for some purpose in the program.
**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");
}
How can I read the config file info.??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许使用 log4cxx::helpers::Properties 中的 getProperty 方法可以工作。
http://logging.apache.org/log4cxx/apidocs/classlog4cxx_1_1helpers_1_1_properties.html
Maybe it will work using the getProperty method from log4cxx::helpers::Properties.
http://logging.apache.org/log4cxx/apidocs/classlog4cxx_1_1helpers_1_1_properties.html