0

Recently, I want to implement a log functionality which is very similar to the log mechanism of Tomcat. I just want to know, how Tomcat implements that different web applications can have different logging configurations and you do not need to worry about them interfering with each other. As I found some info by google before, Tomcat uses its own custom ClassLoaderLogManager which is classloader-aware. And I know this. But through my own experiment that I changed the ClassLoaderLogManager.java and replaced the tomcat-juli.jar, I found that when I called logger.info(""), it seemed that the introduced log interface in my web-app did not have a interaction with ClassLoaderLogManager. So I really just do not know how Tomcat gets this done.

And also, what should I do if want to implement different log outputs by different classloader in just one Java application?

currarpickt
  • 2,290
  • 4
  • 24
  • 39

1 Answers1

0

Tomcat uses its own custom ClassLoaderLogManager which is classloader-aware.

[snip]

So I really just do not know how Tomcat gets this done.

You already know how it does it just that something went wrong in your experiment. Start with a simple test case first and work your way up.

And also, what should I do if want to implement different log outputs by different classloader in just one Java application?

If you just care about outputs then you can create a custom formatter that can switch output based on the current class loader. Then install that formatter on your handlers.

Community
  • 1
  • 1
jmehrens
  • 10,580
  • 1
  • 38
  • 47
  • Thank you so much for your answering. Although there are few people to read and answer this question, I still here give my final solution to this question in order to give some shortcuts to people with same situations like me. The essence of living up to my expectations lies in the procedure of webapp-classloader in Tomcat. The webapp-classloader loads resources and classes in preference to those in common libs, which is different from parent delegation in JVM. – minglei yin Oct 29 '16 at 08:46