[ 
https://issues.apache.org/jira/browse/LOGCXX-439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thorsten Schöning resolved LOGCXX-439.
--------------------------------------
    Resolution: Fixed

I might have an idea what's going on: Watching the file for changes is done in 
a different thread than originally configuring log4cxx and setting up the MDC. 
Data in the MDC is stored per thread, but if the thread watching for file 
changes recognizes those changes, ITSELF reconfigures log4cxx. That means all 
requests to the MDC will be thread-specific and empty.

{quote}
class XMLWatchdog  : public FileWatchdog
{
        public:
                XMLWatchdog(const File& filename) : FileWatchdog(filename)
                {
                }

                /**
                Call DOMConfigurator#doConfigure with the
                <code>filename</code> to reconfigure log4cxx.
                */
                void doOnChange()
                {
                        DOMConfigurator().doConfigure(file,
                                LogManager::getLoggerRepository());
                }
};
{quote}

{quote}
void DOMConfigurator::configureAndWatch(const std::string& filename, long delay)
{
        File file(filename);
#if APR_HAS_THREADS

        if ( xdog )
        {
                APRInitializer::unregisterCleanup(xdog);
                delete xdog;
        }

        xdog = new XMLWatchdog(file);
        APRInitializer::registerCleanup(xdog);
        xdog->setDelay(delay);
        xdog->start();
#else
        DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
#endif
}
{quote}

Not sure if this can easily be fixed, so for the concrete use case mentioned by 
the reporter, I instead suggest using environment variables. Those are per 
process instead of per thread, are available in configuration files as well and 
can be set on runtime. I'm doing this in some of my own apps as well:

{quote}
        <appender       name="monthSpecificLogFile"
                                
class="org.apache.log4j.rolling.RollingFileAppender">
                <rollingPolicy  
class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
                        <param  name="FileNamePattern"
                                        
value="${AppData}\AM-SoFT\GosaPrint\logs\%d{yyyy-MM}.log"
                        />
                </rollingPolicy>
                [...]
        </appender>
{quote}

Because we are trying to reduce the backlog of open issues, I'm closing this 
one right now. If somebody has better ideas to fix this problem, feel free to 
provide your solutions and reopen.

> Dynamic Configuration of Log4cxx XML with Properties is not proper
> ------------------------------------------------------------------
>
>                 Key: LOGCXX-439
>                 URL: https://issues.apache.org/jira/browse/LOGCXX-439
>             Project: Log4cxx
>          Issue Type: Bug
>          Components: Configurator
>    Affects Versions: 0.10.0
>         Environment: Windows XP SP 2/7, Visual Studio 2010.
>            Reporter: balajilbk
>            Priority: Major
>         Attachments: Sample_log4cxx.xml
>
>   Original Estimate: 48h
>  Remaining Estimate: 48h
>
> Dear Team,
> Thanks for the wonderful logging framework.
> In my application, the Log4cxx Configuration XML file contain few fields in 
> appender with %properties{Property Name}.  The properties are set using 
> log4cxx::MDC::put method in my program. When doing the first time 
> configuration, the DOMConfigurator configures the data properly because of 
> the available thread context. 
> But if we update the configuration file dynamically without re-starting the 
> application, the thread is not having any MDC data. Hence the property is 
> empty when re-configuring using dynamic usage of the DOMConfigurator.
> Kindly help me to resolve this issue.
> Thanks in advance.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to