How to enable embedded tomcat logging

前端 未结 5 1562
隐瞒了意图╮
隐瞒了意图╮ 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:29

    You need to include the tomcat-embed-logging-juli-8.0.15.jar in your classpath.

    I used this code to load the logging.properties file and configure the logging externally using the normal java logging approach:

    //Loads custom logging configuration located in a properties file named logging.properties
    try (InputStream inputStream = new FileInputStream("logging.properties")) {
        LogManager.getLogManager().readConfiguration(inputStream);
        System.out.println("Custom logging configuraton loaded successfully");
    } catch (Exception exception) {
        System.err.println ("Custom logging configuration don't found using default system logging configuration.");
    }
    

    For more details about configure the logging.properties use this pages: Tomcat logging, org.apache.juli.FileHandler

    Also you can use the java.util.logging.FileHandler that is also compatible with the juli aproach an has another advanced configuration options: java.util.logging.FileHandler

    There is another jar for use log4j but for me this works fine. Note: I used the tomcat embedded 8.0.15 but there are new versions now.

提交回复
热议问题