有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何关闭jetty调试?

我有一个运行jetty的java应用程序:

public class ServerRunner {

    private final static org.apache.log4j.Logger logger = LoggingUtils.getLogger();

    public static void main(String[] args) throws Exception {
        PromptoConfig.s.initLog();


        final int port = 8082;

        final Server jettyServer = new Server(port);
        final HandlerCollection handlers = new HandlerCollection();

        // Creating the first web application context
        final WebAppContext webappContext = new WebAppContext();

        System.out.println("===== PromptoConfig.s.RESOURCES_BASE " + PromptoConfig.s.RESOURCES_BASE);
        webappContext.setResourceBase(PromptoConfig.s.RESOURCES_BASE);
        webappContext.setContextPath("/");

        System.out.println("===== PromptoConfig.s.WEB_XML_PATH " + PromptoConfig.s.WEB_XML_PATH);
        webappContext.setDefaultsDescriptor(PromptoConfig.s.WEB_XML_PATH);
//        webappContext.setTempDirectory(new File(temp));


        DBSQLConfig.s().DB = com.waze.prompto.config.DBSQLConfig.s.DB;


        webappContext.setExtractWAR(false);
        handlers.addHandler(webappContext);

        // Adding the handlers to the server.
        jettyServer.setHandler(handlers);

        try {
            jettyServer.start();
            jettyServer.join();
        } catch (Exception ex) {
            logger.error("failed to init jetty server", ex);
        } finally {
            jettyServer.destroy();
        }
    }
}

我在intellij控制台的日志调试信息中看到:

633016 [org.eclipse.jetty.server.session.HashSessionManager@22fcf7abTimer] DEBUG org.eclipse.jetty.server.session  - Scavenging sessions at 1496325042425

如何关闭此调试日志


共 (2) 个答案

  1. # 1 楼答案

    如果您使用eclipse中的jetty服务器

    添加配置

    log4j.category.org.eclipse.jetty=error
    

    在文件src/main/resources/log4j中。性质

  2. # 2 楼答案

    您似乎已经在您的环境中配置了log4j

    private final static org.apache.log4j.Logger logger = LoggingUtils.getLogger();
    

    输出格式也不是Jetty内部StdErrLog的默认格式

    你的

    633016 [org.eclipse.jetty.server.session.HashSessionManager@22fcf7abTimer] DEBUG org.eclipse.jetty.server.session  - Scavenging sessions at 1496325042425
    

    码头标准日志

    2017-06-01 14:30:17.978:DBUG:oejs.session:main: SessionManager default maxInactiveInterval=1800
    

    此时,这不再是jetty日志记录配置,而是log4j配置

    只需在log4j.propertieslog4j.xml中将org.eclipse.jetty记录器级别设置为INFO或WARN即可