[英]Logging in tomcat doesn't work
I have fullproject based on spring with using some Controllers, DAO and other web application elements. 我有一个基于spring的fullproject,其中使用了一些Controller,DAO和其他Web应用程序元素。 And now i want to configure log4j2.
现在我想配置log4j2。 I do it:
我做到了:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.1</version>
</dependency>
create log4j2.xml in src/main/resources folder 在src / main / resources文件夹中创建log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<logger name="com.myproject" level="INFO" />
</Loggers>
</Configuration>
and then i create class with main(String [] args) method which have to output some info logs: 然后我用main(String [] args)方法创建类,该类必须输出一些信息日志:
public class MainClass{
public static void main(String[] args){
Logger logger = LogManager.getLogger(MainClass.class.getName());
logger.info("Entering Log4j Example.");
}
}
for run application i use: 对于我使用的运行应用程序:
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<mainClass>com.myproject.MainClass</mainClass>
</configuration>
And all it i do in redactor, which has own console. 以及我在redactor中所做的所有工作,redactor具有自己的控制台。 And deploy it with tomcat7 maven plugin.
并使用tomcat7 maven插件进行部署。
Please say me, do i make it all in correct way or wrong. 请说我,我是否以正确或错误的方式做到了。 And if in correct when i can see result of these logs, because in redactor console i don't see and in tomcat logs too
如果在正确的时候我可以看到这些日志的结果,因为在redactor控制台中我看不到,并且在tomcat日志中也看不到
You forgot the destination appender: 您忘记了目标附加程序:
<Loggers>
<Logger name="com.myproject" level="INFO">
<AppenderRef ref="CONSOLE"/>
</Logger>
</Loggers>
By the way, you have confused a standalone application with a web application . 顺便说一下,您已经将独立应用程序与Web应用程序混淆了。 In Tomcat, you need a web application with servlets, jsp's, etc. You may want to see How To Create A Web Application Project With Maven .
在Tomcat中,您需要一个带有servlet,jsp等的Web应用程序。您可能想看看如何使用Maven创建Web应用程序项目 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.