On Fri, 2007-10-26 at 07:59 +1000, Paul Smith wrote:
On 26/10/2007, at 5:26 AM, Joshua ChaitinPollak wrote:
If you had the time, crafting a unit test based on the other unit
tests in the bridge project would be most useful to demonstrate a
problem if there was one.. ?

Perhaps an example of your log4j configuration process (config file)
and an example of the TRACE level logging event being output to a file?

cheers,

Paul

Paul,

Below is a class I've created that demonstrates the problem, along with
simple instructions on how to create a project to execute the code. When
I run the test I see:

Running org.apache.AppTest
2007-10-29 18:22:30,474 [10] TRACE test.logger - Finest
2007-10-29 18:22:30,478 [10] DEBUG test.logger - Finer
2007-10-29 18:22:30,479 [10] DEBUG test.logger - Fine
2007-10-29 18:22:30,479 [10] WARN  test.logger - Warning
2007-10-29 18:22:30,479 [10] ERROR test.logger - Severe
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.275
sec

But I'm setting:

loggingProperties.setProperty("log4j.logger.test.logger", "WARN");

So I would expect to only see the Warning and Severe lines.

Any help would be appreciated.

-Josh

Here are the steps I took:

1) I created a blank Maven project:
"mvn archetype:create -DgroupId=org.apache -DartifactId=JulTest"
2) I added these dependencies:
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>apache-log4j-component</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging</groupId>
            <artifactId>apache-jul-log4j-bridge</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
3) I edited AppTest.testApp() to do the following:
    public void testApp()
    {
        App.main(null);
        assertTrue( true );
    }
4) And I changed App.java to be:
-------------------------------------------------------------

package org.apache;

import java.util.Properties;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.log4j.*;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.spi.RepositorySelector;
import org.apache.logging.julbridge.JULLog4jBridge;


public class App
{
    private final static Object repositorySelectorGuard = new Object();
final static LoggerRepository repositoryExImpl = new LoggerRepositoryExImpl(LogManager.getLoggerRepository());

    public static void mergeLogging() {
        JULLog4jBridge.assimilate();

         LogManager.setRepositorySelector(new RepositorySelector() {

                public LoggerRepository getLoggerRepository() {
                    return repositoryExImpl;
                }
            }, repositorySelectorGuard);
    }

    public static void main( String[] args )
    {
        mergeLogging();

        Properties loggingProperties = new Properties();

loggingProperties.setProperty("log4j.rootLogger", "WARN,console"); loggingProperties.setProperty("log4j.appender.console", "org.apache.log4j.ConsoleAppender"); loggingProperties.setProperty ("log4j.appender.console.layout", "org.apache.log4j.PatternLayout"); loggingProperties.setProperty ("log4j.appender.console.layout.ConversionPattern", "%d [%t] %-5p %c - %m%n"); loggingProperties.setProperty("log4j.logger.test.logger", "WARN");

        LogManager.resetConfiguration();
        PropertyConfigurator.configure(loggingProperties);

        Logger logger = Logger.getLogger("test.logger");

        logger.finest("Finest");
        logger.finer("Finer");
        logger.fine("Fine");
        logger.warning("Warning");
        logger.severe("Severe");
    }
}


--
Joshua ChaitinPollak
Software Engineer
Kiva Systems



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to