Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not set logger by myself #566

Closed
ryshi opened this issue Aug 13, 2016 · 3 comments
Closed

can not set logger by myself #566

ryshi opened this issue Aug 13, 2016 · 3 comments

Comments

@ryshi
Copy link

ryshi commented Aug 13, 2016

Version: 1.59.0
JDK:1.7.0_70
Tomcat:7.0.x


Background: There is a log4j-1.x.jar in ${CATALINA_BASE}/lib which means tomcat log uses log4j to write log and my context can find log4j classes. My own application uses slf4j + logback.
When I put myapp.war into tomcat,an exception is thrown out

java.lang.NoSuchMethodError: net.bull.javamelody.Log4JAppender.setThreshold(Lorg/apache/log4j/Priority;)V
        at net.bull.javamelody.Log4JAppender.<init>(Log4JAppender.java:42)
        at net.bull.javamelody.Log4JAppender.<clinit>(Log4JAppender.java:34)
        at net.bull.javamelody.FilterContext.initLogs(FilterContext.java:283)
        at net.bull.javamelody.FilterContext.<init>(FilterContext.java:70)

I found that there is a param called logger-class can be set, I've done it and failed.

I added this to web.xml, got the same exception

<context-param>
    <param-name>javamelody.logger-class</param-name>
    <param-value>net.bull.javamelody.LogbackLogger</param-value>
</context-param>

I found codes in FilterContext.java

    private static void initLogs() {
        // on branche le handler java.util.logging pour le counter de logs
        LoggingHandler.getSingleton().register();

        if (LOG.LOGBACK_ENABLED) {
            // si logback est disponible on branche aussi l'appender pour le counter de logs
            LogbackAppender.getSingleton().register();
        }

        if (LOG.LOG4J_ENABLED) {
            // si log4j est disponible on branche aussi l'appender pour le counter de logs
            Log4JAppender.getSingleton().register();
        }

        if (LOG.LOG4J2_ENABLED) {
            // si log4j2 est disponible on branche aussi l'appender pour le counter de logs
            Log4J2Appender.getSingleton().register();
        }

        LOG.debug("log listeners initialized");
    }

Is there any way to set logger by myself or I missed something ?

Thanks for reply.

@evernat
Copy link
Member

evernat commented Aug 16, 2016

The logger-class parameter is used when javamelody is logging, and not in this case when registering listeners for messages logged by the application. So the logger-class parameter can not help you in this case.
So I suggest that you look for all jars which contains log4j classes such as log4j* and slf4j* in your webapp and in tomcat/lib.
Or if you give the source of a simple project (using maven if possible) + tomcat/lib to reproduce the issue, I will look for the root cause.
Anyway, let me know what we can do with this issue.

@ryshi
Copy link
Author

ryshi commented Aug 22, 2016

I made a simple test to reproduce this issue jmtest.zip
And you can follow this doc to config tomcat + log4j
logfile: tomcat/logs/localhost

java.lang.NoSuchMethodError: net.bull.javamelody.Log4JAppender.setThreshold(Lorg/apache/log4j/Priority;)V
        at net.bull.javamelody.Log4JAppender.<init>(Log4JAppender.java:42)
        at net.bull.javamelody.Log4JAppender.<clinit>(Log4JAppender.java:34)
        at net.bull.javamelody.FilterContext.initLogs(FilterContext.java:283)
        at net.bull.javamelody.FilterContext.<init>(FilterContext.java:70)
        at net.bull.javamelody.MonitoringFilter.init(MonitoringFilter.java:112)
        at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)

@evernat
Copy link
Member

evernat commented Aug 28, 2016

I have reproduced the issue.
But first, you include in the webapp log4j-over-slf4j.jar which contains empty log4j classes and you include log4j.jar in tomcat/lib which of cource contains log4j classes. The clash between two versions of Log4J classes can ask for problems.

Anyway, the problem is that your webapp includes old versions of log4j-over-slf4j and of slf4j-api. Upgrade them to the latest versions (1.7.21) and your issue is gone.
In fact, the issue was fixed by Slf4J here:
qos-ch/slf4j@fd4ce79#diff-5799ce79ad50348887976edbc73cb38d

@evernat evernat closed this as completed Aug 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants