logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 53781] Need multiple logger instances in multithreaded environment
Date Mon, 27 Aug 2012 17:29:56 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=53781

--- Comment #4 from Raj <rlolage@mobileiron.com> ---
This is a pretty unique scenario.

I use a RollingFileAppender to route the log messages to a file. Following is
the code in the BeforeMethod. The appender "FILE" is configured in the
log4j.xml

    @BeforeMethod (alwaysRun = true)
    public void beforeCreateSeparateLogFile(Method method) 
    {

        String fileName = method.getName(); 
        String fileSep = System.getProperty("file.separator");
        RollingFileAppender rfa = (RollingFileAppender)
Logger.getRootLogger().getAppender("FILE");
        rfa.setFile("TestOutput" + fileSep + fileName + ".log");
        rfa.activateOptions();

        log.info("STARTING TESTCASE : " + method.getName());
        log.info("");

    }


By doing this, I can get the log messages per test case in its own log file. I
do this because of specific test framework related reasons and easier
troubleshooting when a test case fails.

Now, imagine the above code getting executed in a multithreaded way. Since
there is only one logger instance, some other thread can change the route of
the messages. That way the messages get mixed up and end up in a wrong file.
The reason why I suggested having multiple instances is because every instance
can be in its own thread without affecting each  other.


I hope that helps understanding the problem that I am facing.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message