[jboss-jira] [JBoss JIRA] (JBLOGGING-94) JBoss Logging does not detect log4j 2.0

Henry Clout (JIRA) jira-events at lists.jboss.org
Tue Apr 30 10:12:54 EDT 2013


     [ https://issues.jboss.org/browse/JBLOGGING-94?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henry Clout updated JBLOGGING-94:
---------------------------------

    Description: 
The class org.jboss.logging.LoggerProviders checks for the presence of log4j using the code:

{code}
   private static LoggerProvider tryLog4j(final ClassLoader cl) throws ClassNotFoundException {
        Class.forName("org.apache.log4j.LogManager", true, cl);
        // JBLOGGING-65 - slf4j can disguise itself as log4j.  Test for a class that slf4j doesn't provide.
        Class.forName("org.apache.log4j.Hierarchy", true, cl);
        return new Log4jLoggerProvider();
    }
{code}

However, despite having the log4j-1.2-api-2.0.jar bridge included, this fails as the class org.apache.log4j.Hierarchy is not present in log4j 2.0.

I worked around this by forcing JBoss logging to use slf4j (which is then proxied to log4j) by setting the -Dorg.jboss.logging.provider=slf4j option.  

As a proper fix, however, how about checking for a class that is included in log4j 1.2, 2.0 but not slf4j? org.apache.log4j.config.PropertySetter seems to tick the box.

I tested changing the afore mentioned method to:

{code}
    private static LoggerProvider tryLog4j(final ClassLoader cl) throws ClassNotFoundException {
        Class.forName("org.apache.log4j.LogManager", true, cl);
        // JBLOGGING-65 - slf4j can disguise itself as log4j.  Test for a class that slf4j doesn't provide.
        Class.forName("org.apache.log4j.config.PropertySetter", true, cl);
        return new Log4jLoggerProvider();
    }
{code}

And indeed I started receiving logging messages from Hibernate (via JBoss logging.)

  was:
The class org.jboss.logging.LoggerProviders checkes for the presence of log4j using the code:

{code}
   private static LoggerProvider tryLog4j(final ClassLoader cl) throws ClassNotFoundException {
        Class.forName("org.apache.log4j.LogManager", true, cl);
        // JBLOGGING-65 - slf4j can disguise itself as log4j.  Test for a class that slf4j doesn't provide.
        Class.forName("org.apache.log4j.Hierarchy", true, cl);
        return new Log4jLoggerProvider();
    }
{code}

However, despite having the log4j-1.2-api-2.0.jar bridge included, this fails as the class org.apache.log4j.Hierarchy is not present in log4j 2.0.

I worked around this by forcing JBoss logging to use slf4j (which is then proxied to log4j) by setting the -Dorg.jboss.logging.provider=slf4j option.  

As a proper fix, however, how about checking for a class that is included in log4j 1.2, 2.0 but not slf4j? org.apache.log4j.config.PropertySetter seems to tick the box.

I tested changing the afore mentioned method to:

{code}
    private static LoggerProvider tryLog4j(final ClassLoader cl) throws ClassNotFoundException {
        Class.forName("org.apache.log4j.LogManager", true, cl);
        // JBLOGGING-65 - slf4j can disguise itself as log4j.  Test for a class that slf4j doesn't provide.
        Class.forName("org.apache.log4j.config.PropertySetter", true, cl);
        return new Log4jLoggerProvider();
    }
{code}

And indeed I started receiving logging messages from Hibernate (via JBoss logging.)


    
> JBoss Logging does not detect log4j 2.0
> ---------------------------------------
>
>                 Key: JBLOGGING-94
>                 URL: https://issues.jboss.org/browse/JBLOGGING-94
>             Project: JBoss Logging
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: jboss-logging-log4j
>    Affects Versions: 3.1.2.GA
>         Environment: Hibernate 
>            Reporter: Henry Clout
>            Assignee: David Lloyd
>
> The class org.jboss.logging.LoggerProviders checks for the presence of log4j using the code:
> {code}
>    private static LoggerProvider tryLog4j(final ClassLoader cl) throws ClassNotFoundException {
>         Class.forName("org.apache.log4j.LogManager", true, cl);
>         // JBLOGGING-65 - slf4j can disguise itself as log4j.  Test for a class that slf4j doesn't provide.
>         Class.forName("org.apache.log4j.Hierarchy", true, cl);
>         return new Log4jLoggerProvider();
>     }
> {code}
> However, despite having the log4j-1.2-api-2.0.jar bridge included, this fails as the class org.apache.log4j.Hierarchy is not present in log4j 2.0.
> I worked around this by forcing JBoss logging to use slf4j (which is then proxied to log4j) by setting the -Dorg.jboss.logging.provider=slf4j option.  
> As a proper fix, however, how about checking for a class that is included in log4j 1.2, 2.0 but not slf4j? org.apache.log4j.config.PropertySetter seems to tick the box.
> I tested changing the afore mentioned method to:
> {code}
>     private static LoggerProvider tryLog4j(final ClassLoader cl) throws ClassNotFoundException {
>         Class.forName("org.apache.log4j.LogManager", true, cl);
>         // JBLOGGING-65 - slf4j can disguise itself as log4j.  Test for a class that slf4j doesn't provide.
>         Class.forName("org.apache.log4j.config.PropertySetter", true, cl);
>         return new Log4jLoggerProvider();
>     }
> {code}
> And indeed I started receiving logging messages from Hibernate (via JBoss logging.)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list