Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help configuring the log4cplus configuration file (properties file)

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.

like image 701
cchampion Avatar asked May 13 '10 20:05

cchampion


2 Answers

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
like image 105
cchampion Avatar answered Oct 07 '22 17:10

cchampion


Original question was answered 2010. Log4cplus documentation for configuration is still a little hard to find... For anyone browsing through here:


Here is a detailed example for log4cplus configuration files:

http://log4cplus.sourceforge.net/docs/html/classlog4cplus_1_1PropertyConfigurator.html#a21e8e6b1440cc7a8a47b8fd14c54b239

like image 44
Konstantin A. Magg Avatar answered Oct 07 '22 17:10

Konstantin A. Magg