我在spring应用程序中使用log4j。豆子创造&其他信息正在控制台和显示器中正确显示写在磁盘上,但在处理程序方法中 log.info& log.debug无效。我在控制台中看不到任何输出。谁能告诉我为什么?
log4j.properties
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\logging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSSS} %p %t %c \u2013 %m%n
# Root logger option
log4j.rootLogger=debug, file, stdout
ClinicController.java
package com.petclinic.controller;
//ClinicController is the generic controller for the web app
@Controller
public class ClinicController {
@Autowired
private ClinicService clinicService;
private static Logger logger = LogManager.getLogger("ClinicController");
//Custom Handler for the welcome Page
@RequestMapping("/welcome")
public String welcomeHandler(HttpServletRequest request)
{
logger.info(request.getServletPath());
System.out.println("Inside Welcome Controller");
System.out.println(request.getServletPath());
logger.debug("Inside Clinic Controller Welcome Controller");
return "welcome";
}
}
我可以在控制台中看到System.out语句,但不能看到logger.info&调试。
logger.info(request.getServletPath());
logger.debug("Inside Clinic Controller Welcome Controller");
我错过了什么吗?
log snippet
2014-02-26 00:02:32.0135 DEBUG "http-bio-8080"-exec-7 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping – Matching patterns for request [/welcome.jsp] are [/welcome.*]
2014-02-26 00:02:32.0143 DEBUG "http-bio-8080"-exec-7 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping – Mapping [/welcome.jsp] to handler 'com.petclinic.controller.ClinicController@dd02e8'
2014-02-26 00:02:32.0152 DEBUG "http-bio-8080"-exec-7 org.springframework.web.servlet.DispatcherServlet – Last-Modified value for [/PetClinic/forms/welcome.jsp] is: -1
2014-02-26 00:02:32.0163 DEBUG "http-bio-8080"-exec-7 org.springframework.web.servlet.DispatcherServlet – DispatcherServlet with name 'dispatcher' processing GET request for [/PetClinic/forms/welcome.jsp]
2014-02-26 00:02:32.0193 DEBUG "http-bio-8080"-exec-7 org.springframework.web.bind.annotation.support.HandlerMethodInvoker – Invoking request handler method: public java.lang.String com.petclinic.controller.ClinicController.welcomeHandler(javax.servlet.http.HttpServletRequest)
Inside Welcome Controller
/forms
2014-02-26 00:02:32.0199 DEBUG "http-bio-8080"-exec-7 org.springframework.beans.factory.support.DefaultListableBeanFactory – Invoking afterPropertiesSet() on bean with name 'welcome'
2014-02-26 00:02:32.0200 DEBUG "http-bio-8080"-exec-7 org.springframework.web.servlet.DispatcherServlet – Rendering view [org.springframework.web.servlet.view.JstlView: name 'welcome'; URL [/WEB-INF/view/welcome.jsp]] in DispatcherServlet with name 'dispatcher'
2014-02-26 00:02:32.0211 DEBUG "http-bio-8080"-exec-7 org.springframework.web.servlet.view.JstlView – Forwarding to resource [/WEB-INF/view/welcome.jsp] in InternalResourceView 'welcome'
2014-02-26 00:02:32.0278 DEBUG "http-bio-8080"-exec-7 org.springframework.web.servlet.DispatcherServlet – Successfully completed request
2014-02-26 00:02:32.0280 DEBUG "http-bio-8080"-exec-7 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter – Closing single Hibernate Session in OpenSessionInViewFilter
答案 0 :(得分:0)
1。)您的log4j.properties文件位于何处?在构建WAR时,log4j.properties文件应位于WEB-INF / classes文件夹的根目录中。
2.。根据archie hicox的建议,你应该将rootlogger更改为log4j.rootLogger = debug,file,stdout(不含信息)