Reading Property Info in Log4cxx

北慕城南 提交于 2020-01-03 05:02:10

问题


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.??


回答1:


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



来源:https://stackoverflow.com/questions/6172932/reading-property-info-in-log4cxx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!