[英]No logs of servlets in Eclipse starting Tomcat
I am using我在用
and I am starting to write a servlet, which runs in the Tomcat container.我开始编写一个 servlet,它在 Tomcat 容器中运行。 When I run it in Ecplise ( Debug on Server ) I can see some logging output from Tomcat.
当我在 Ecplise(在服务器上调试)中运行它时,我可以看到一些来自 Tomcat 的日志记录 output。 Like
喜欢
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()
... ...
The servlet runs fine and the start looks like this: 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;
}
}
But I do not see the debug line .但我没有看到调试行。
For logging I am using slf4j 1.7 and log4j2 .对于日志记录,我使用slf4j 1.7 和 log4j2 。 I have the following
log4j2.xml
我有以下
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Do I just need a different console view in Eclipse?我只需要在 Eclipse 中使用不同的控制台视图吗? Anything wrong with my configuration and how can I debug it?
我的配置有什么问题,我该如何调试它?
Two steps for a solution for this problem:解决此问题的两个步骤:
We are talking about Eclipse, so I have added the -Dlog4j2.debug=true
flag to我们正在谈论 Eclipse,所以我添加了
-Dlog4j2.debug=true
标志
Run Configurations -> Arguments (tab)运行配置 -> Arguments(选项卡)
Then I could see that log4j2 needs the log4j2-web
dependency in this setup.然后我可以看到 log4j2 在此设置中需要
log4j2-web
依赖项。 And it complained that it could not see a configuration file, so I added the log4j2.xml
the right place (in the classpath).它抱怨它看不到配置文件,所以我在正确的位置(在类路径中)添加了
log4j2.xml
。 (Eclipse: right click on src/main/resources -> new 'other' -> xml file .) This folder was already in my classpath, the formerly used one not. (Eclipse:右键单击 src/main/resources -> new 'other' -> xml 文件。)这个文件夹已经在我的类路径中,以前使用的不是。
When there is no configuration file it uses it sdt configuration, which has log level error as default.当没有配置文件时,它使用它的 sdt 配置,默认有日志级别错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.