How to enable embedded tomcat logging

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

    By default the embedded Tomcat uses the logging configuration provided by the JDK. If you haven't changed the configuration only a ConsoleHandler is configured. If you wanted to programmatically add a FileHandler you can add it to the root logger. Here's an example that writes to the file catalina.out by appending the messages on INFO level. This works for Tomcat 6.x and 7.x.

    Logger logger = Logger.getLogger("");
    Handler fileHandler = new FileHandler("catalina.out", true);
    fileHandler.setFormatter(new SimpleFormatter());
    fileHandler.setLevel(Level.INFO);
    fileHandler.setEncoding("UTF-8");
    logger.addHandler(fileHandler);
    

提交回复
热议问题