Help configuring the log4cplus configuration file (properties file)

cchampion picture cchampion · May 13, 2010 · Viewed 14k times · Source

I created a new Logger object like this:

log4cplus::Logger m_WebAccessLogger;  //a class member

Then in the constructor initialization list I do:

m_WebAccessLogger(log4cplus::Logger::getInstance("WebAccess")

This works fine, it logs as expected. What I'm having trouble with is, I want to configure the log4cplus.properties file so that everything for "WebAccess" will go to a separate log file (right now it goes to the default log file where everything else goes).

I can't seem to find the documentation for how to configure these properties files, so I need help please!

Here's my current log properties, how can I tell it to have "WebAccess" go to a different file?

log4cplus.rootLogger=DEBUG, ROLLING
log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
log4cplus.appender.STDOUT.layout.ConversionPattern=%d{%m/%d/%y %H:%M:%S} [%t] %-5p %c{2} %%%x%% - %m [%l]%n
log4cplus.appender.STDOUT.layout.ConversionPattern=%d{%H:%M:%S} [%t] - %m%n

log4cplus.appender.ROLLING=log4cplus::RollingFileAppender
log4cplus.appender.ROLLING.MaxFileSize=5MB
log4cplus.appender.ROLLING.MaxBackupIndex=5
#log4cplus.appender.ROLLING.layout.ConversionPattern=%d{%m/%d/%y %H:%M:%S} [%t] %-5p %c{2} %%%x%% - %m [%l]%n
log4cplus.appender.ROLLING.layout=log4cplus::TTCCLayout
log4cplus.appender.ROLLING.File=c:\projects\ArchiveService\IArchive.log

Something like:
WebAccess.File=c:\projects\ArchiveService\webaccess.log
or
log4cplus.WebAccess.File=webaccess.log

I know log4cplus is simular to log4j, that why I put that as a Tag for this one.

Answer

cchampion picture cchampion · May 13, 2010

I figured it out by guessing.

log4cplus.rootLogger=DEBUG, ROLLING
log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
log4cplus.appender.STDOUT.layout.ConversionPattern=%d{%m/%d/%y %H:%M:%S} [%t] %-5p %c{2} %%%x%% - %m [%l]%n
log4cplus.appender.STDOUT.layout.ConversionPattern=%d{%H:%M:%S} [%t] - %m%n

log4cplus.appender.ROLLING=log4cplus::RollingFileAppender
log4cplus.appender.ROLLING.MaxFileSize=5MB
log4cplus.appender.ROLLING.MaxBackupIndex=5
#log4cplus.appender.ROLLING.layout.ConversionPattern=%d{%m/%d/%y %H:%M:%S} [%t] %-5p %c{2} %%%x%% - %m [%l]%n
log4cplus.appender.ROLLING.layout=log4cplus::TTCCLayout
log4cplus.appender.ROLLING.File=c:\projects\ArchiveService\Debug\ImageArchive.log

log4cplus.logger.WebAccess=DEBUG, R2
log4cplus.appender.R2=log4cplus::RollingFileAppender
log4cplus.appender.R2.File=c:\projects\ArchiveService\Debug\webaccess.log
log4cplus.appender.R2.MaxFileSize=5MB
log4cplus.appender.R2.MaxBackupIndex=5
#log4cplus.appender.R2.layout=log4cplus::TTCCLayout