eclipse中没有servlet的日志启动tomcat

kwvwclae  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(426)

我正在使用
汤姆猫9
eclipse版本:2020-09(4.17.0)
apache maven 3.6.3版
我开始编写一个servlet,它在tomcat容器中运行。当我在ecplise(服务器上调试)中运行它时,我可以看到tomcat的一些日志输出。喜欢

INFO: Initializing ProtocolHandler ["http-nio-8080"]
Dec 08, 2020 4:21:34 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-127.0.0.1-8009"]
Dec 08, 2020 4:21:34 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [1291] milliseconds
Dec 08, 2020 4:21:34 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Dec 08, 2020 4:21:34 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.39]
Dec 08, 2020 4:21:36 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Dec 08, 2020 4:21:38 PM org.glassfish.jersey.server.wadl.WadlFeature configure
WARNING: JAXBContext implementation could not be found. WADL feature is disabled.
Dec 08, 2020 4:21:39 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory [/home/myname/bin/tomcat/apache-tomcat-9.0.39/webapps/examples]
Dec 08, 2020 4:21:39 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Dec 08, 2020 4:21:39 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()

... ...

servlet运行良好,其开始如下所示:

public class MyMain extends Application {

    private final static Logger logger = LoggerFactory.getLogger(SdpApiMain.class);

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> s = new HashSet<Class<?>>();
        s.add(Test.class);
        s.add(User.class);
        logger.debug("We are in main class, collectiong resources.");
        return s;
    }
}

但是我没有看到调试行。
对于日志记录,我使用slf4j1.7和log4j2。我有以下几点 log4j2.xml ```

x0fgdtte

x0fgdtte1#

解决此问题的两个步骤:
我们讨论的是eclipse,所以我添加了 -Dlog4j2.debug=true 标记到
运行配置->参数(选项卡)
然后我可以看到log4j2需要 log4j2-web 此设置中的依赖项。它抱怨看不到配置文件,所以我添加了 log4j2.xml 正确的位置(在类路径中)(eclipse:右键单击src/main/resources->new'other'->xml文件。)这个文件夹已经在我的类路径中,以前使用的那个没有。
当没有配置文件时,它使用sdt配置,默认为日志级别错误。

相关问题