How to enable embedded tomcat logging

前端 未结 5 1564
隐瞒了意图╮
隐瞒了意图╮ 2021-01-22 23:36

I m using embedded tomcat in my java application. below is my source code. however tomcat is not generating any log.

        embedded = new Embedded();
        e         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-23 00:13

    I had just to figure out, how I can control the logging of the embedded Tomcat the same way the standalone version is doing it.

    You will need the tomcat-juli.jar, because it has a custom LogManager in it. This LogManager has advantages, since it is capable of registering multiple FileHandlers. So it enables you to separate Logs per WebApp.

    It is not enough to just include the tomcat-juli.jar, but you also need to activate its LogManager. This would be done through a JVM-Parameter:

    -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

    Now it is possible to register FileHandlers like shown in the Tomcat documentation.

    With an additional JVM-Parameter you can set the path to the logging.properties-File:

    -Djava.util.logging.config.file=/logs/logging.properties


    It is also possible to load the .properties-File programmatically, but then you need to set a java.util.logging.config.class with a JVM-Parameter, like above. In it's constructor you then must call LogManager.readProperties(...). Look here for more information.

    Best regards

提交回复
热议问题