How to parse rollingpolicy and triggering policy from log4j properties

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to parse rollingpolicy and triggering policy from log4j properties

yagamiram
This post has NOT been accepted by the mailing list yet.
 0 down vote favorite
       

The below code doesn't run when I include the Fixed rolling policy and size based triggering policy.

I don't understand how the log4cxx parse the properties file. The code runs well when I use org.apache.log4j.RollingAppender. But when I specify the org.apache.log4j.rolling.RollingAppender, it fails to read the attributes that I specify in the rolling policy and triggering policy.

Moreover, the code takes the values of rolling policy and triggering policy when the configuration is written in XML format.

Note: I don't know what version of log4j/log4cxx installed in my system. It is combined with ROS.

#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>

using namespace log4cxx;
using namespace log4cxx::helpers;

// Define static logger variable
LoggerPtr loggerMyMain(Logger::getLogger( "main"));
LoggerPtr loggerFunctionA(Logger::getLogger( "functionA"));

void functionA()
{
    LOG4CXX_INFO(loggerFunctionA, "Executing functionA.");
}

int main()
{
    int value = 5;

    // Load properties style configuration file using PropertyConfigurator
    PropertyConfigurator::configure("Log4cxxConfig.cfg");

    LOG4CXX_TRACE(loggerMyMain, "this is a debug message for detailed code discovery. Value=" << value);
    LOG4CXX_DEBUG(loggerMyMain, "this is a debug message.");
    LOG4CXX_INFO (loggerMyMain, "this is a info message, ignore. Value=" << value);
    LOG4CXX_WARN (loggerMyMain, "this is a warn message, not too bad.");
    LOG4CXX_ERROR(loggerMyMain, "this is a error message, something serious is happening.");
    LOG4CXX_FATAL(loggerMyMain, "this is a fatal message!!!");

    functionA();

    return 0;
}

The properties file is:

log4j.rootLogger=all, rootConsoleAppender, rootFileAppender
# Name of appender is the fully.qualified.name.of.appender.class
log4j.appender.rootConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.rootConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.rootConsoleAppender.layout.ConversionPattern=%d %-5p [%c] - %m%n

log4j.appender.rootFileAppender=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.rootFileAppender.File=appxLogFile.log
log4j.appender.rootFileAppender.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.rootFileAppender.rollingPolicy.FileNamePattern=yagami-kuni.%i.log.gz
log4j.appender.rootFileAppender.rollingPolicy.ActiveFileName=appxLogFile.log
log4j.appender.rootFileAppender.rollingPolicy.MaxIndex=10
log4j.appender.rootFileAppender.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.rootFileAppender.triggeringPolicy.MaxFileSize=10
log4j.appender.rootFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.rootFileAppender.ConversionPattern=%d %-5p %C{2} (%F:%L) - %m%n
Loading...