Re: [Log4cplus-devel] Overriding log level with config file causing loss of logging
Logging Framework for C++
Brought to you by:
wilx
|
From: Václav Z. <vha...@gm...> - 2014-05-10 06:09:49
|
On 8.5.2014 21:45, Ciummo, Lawrence wrote:
> I've got a properties file for my logger that has the following in it:
>
>
>
> log4cplus.logger.memory=TRACE
>
> ### next two lines commented out
>
> #log4cplus.appender.memory.layout=log4cplus::PatternLayout
>
> #log4cplus.appender.memory.layout.ConversionPattern=%d{%m/%d/%y
> %H:%M:%S} [%t]
>
>
>
> I want to use it solely to change the log level when the logger is
> created -- the logger already has a rolling file appender attached at
> startup.
>
>
>
> When the file is present -- I lose all logging -- it appears (I'm
> guessing) that there are no more appenders.
>
>
>
> Here's the code for processing the properties file (called
> memory.properties). Note the log level DOES appear to change
> properly, no logs are no longer getting written.
>
>
>
> Thanks
>
> lc
>
>
>
> // Override logger properties with _config_ file
>
> *struct*statbuffer;
>
> *if*(0 == *stat*(/logname/.c_str(), &buffer))
>
> {
>
> ostringstreampropFile;
>
> propFile << /logger_name/<< ".properties";
>
>
> log4cplus::PropertyConfigurator::*doConfigure*(propFile.str());
>
> log4cplus::LogLevellevel = __mem_log.*getLogLevel*();
>
> stringlev =
> log4cplus::*getLogLevelManager*().*toString*(level);
>
> ostringstreammsg;
>
> msg << "Log level set from memory.properties file to "<< lev;
>
> cerr << msg.str() << *endl*;
>
> __mem_log.*forcedLog*(log4cplus::TRACE_LOG_LEVEL,
> msg.str()); // <<< never see this even at TRACE level
>
> }
>
The |doConfigure()| wipes out the existing configuration. You can change
log level by manipulation the logger in code yourself.
--
VZ
|