Raymond
Raymond

Reputation: 614

Logging Log4j For Each Executed Class

I am working with Java and I have an xml file that will execute some classes.

This is the example style of the xml

    <test name="Test1">
    <classes>
        <class name="com.foo.bar.test1"></class>
    </classes>
</test> 

<test name="Test2">
    <classes>
        <class name="com.foo.bar.test2"></class>
    </classes>
</test> 

<test name="Test3">
    <classes>
        <class name="com.foo.bar.test3"></class>
    </classes>
</test> 

I had been able to do logging with Log4j but I only set it on the log4j.properties, so all log is appended altogether.

I would like to have log file for each class that is executed.

Any idea on how to do this?

Thank you

Upvotes: 0

Views: 55

Answers (1)

Isaac
Isaac

Reputation: 16736

Since Log4J is only initialized once within the life of a classloader, the only way you can achieve this effect would be to dynamically change the Log4J configuration throughout the program that runs those tests (the program I'm referring to is the program that you're writing for parsing the XML file and process each class).

Refer to Log4J's Javadocs for information about dynamically configuring Log4J.

Also, keep in mind that, since the Log4J is scoped within a classloader, you won't be able to run those "test" classes concurrently, unless you start creating and initializing classloaders on the fly.

Upvotes: 1

Related Questions