将记录器与Spring Template MVC项目集成 [英] Integrating logger with Spring Template MVC project

查看:81
本文介绍了将记录器与Spring Template MVC项目集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了很多文章,并尝试了许多方法,但是仍然无法记录我的代码流.原因可能是由于各种见解使我感到困惑.

I read a lot of posts and tried a lot of approaches but still I am unable to log my code flow. The reason could be that I got confused due to various opinions.

我的WebContent/conf/log4j.properties

My WebContent/conf/log4j.properties

# Direct log messages to a log file
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=D:/mylog.log
log4j.appender.rollingFile.MaxFileSize=2MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.Threshold=debug
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
log4j.rootLogger = INFO, rollingFile

我的/WEB-INF/web.xml

My /WEB-INF/web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SpringSort</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

  <servlet>
        <servlet-name>sort</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>sort</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

</web-app>

控制器Controller.java的一部分

A part of my controller Controller.java

private static final Logger logger = LoggerFactory.getLogger(Controller.class);
System.out.println(logger);
System.out.println(logger.isDebugEnabled());
logger.info("Logger Initiliazed");

System.out.println(logger);提供参考地址,而
System.out.println(logger.isDebugEnabled());给出true. 但是没有创建日志文件.

The System.out.println(logger); gives a reference address and the
System.out.println(logger.isDebugEnabled()); gives true. But no log file is being created.

有人可以帮我吗?

推荐答案

本教程中提到的缺陷是针对Maven的(因此,如果您不使用maven,请务必在您的构建路径中使用log4j jar).

Depencies mentioned in the tutorial are for Maven (so if you don't use maven just be sure to have log4j jars in your buildpath).

另一个简单的教程将log4j添加到项目中,然后在

Another simple tutorial to add log4j to your project and then on how to configure it.

这篇关于将记录器与Spring Template MVC项目集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆