简体   繁体   English

log4j信息级别和调试不起作用

[英]log4j info level & debug not working

I am using log4j in a spring application. 我在春季应用程序中使用log4j。 The bean creation & other information is being displayed correctly in the console & written on the disk but in the handler method the log.info & log.debug are not working. Bean创建和其他信息在控制台中正确显示并写入磁盘,但是在处理程序方法中log.info和log.debug无法正常工作。 I see no output in the console. 我在控制台中看不到任何输出。 Can anyone tell me why? 谁能告诉我为什么?

log4j.properties 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 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";
    }
}

I can see System.out statements in the console but not logger.info & debug. 我可以在控制台中看到System.out语句,但不能看到logger.info和debug。

logger.info(request.getServletPath());
logger.debug("Inside Clinic Controller Welcome Controller");

Am I missing something? 我想念什么吗?

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

1.) Where is your log4j.properties file located? 1.)您的log4j.properties文件位于哪里? As you build a WAR, your log4j.properties file should be in the root of the WEB-INF/classes folder. 在构建WAR时,您的log4j.properties文件应位于WEB-INF / classes文件夹的根目录中。

2.) As suggested by archie hicox, you should change rootlogger to log4j.rootLogger=debug, file, stdout (without info) 2.)如archie hicox所建议,您应该将rootlogger更改为log4j.rootLogger = debug,file,stdout(无信息)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM