Help configuring the log4cplus configuration file (properties file)
Asked Answered
P

2

6

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.

Prosperity answered 13/5, 2010 at 20:14 Comment(1)
How are you able to compile this line? m_WebAccessLogger(log4cplus::Logger::getInstance("WebAccess")) ? Log4cplus doesn't provide any such method.Rochelle
P
7

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
Prosperity answered 13/5, 2010 at 20:38 Comment(1)
Sad this seems to be the only way to figure out the log properties file!Clubbable
K
2

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

Klos answered 9/3, 2018 at 10:35 Comment(1)
Thanks for the link - recommended reading for all working with log4cplus!Maiden

© 2022 - 2024 — McMap. All rights reserved.