springboot 加入log4j

pom信息中引入:



       
            org.springframework.boot
            spring-boot-starter-web
            
                
                    org.springframework.boot
                    spring-boot-starter-logging
                
            
        
        
            org.springframework.boot
            spring-boot-starter-log4j
        
       
            org.slf4j
            slf4j-api
        

        
            org.slf4j
            slf4j-jdk14
            compile
        

        
            commons-logging
            commons-logging
            1.1.1
        

        
            log4j
            log4j
            1.2.17
        

log4j.properties

log4j.rootLogger=WARN, stdout
# log4j.rootLogger=WARN, stdout, logfile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=target/spring.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

 

 

java 引用

 


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
public class TestController {
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);
    @PostConstruct()
    public  void init() {
        System.out.println("初始化");
    }


    @ControllerPointcut(description = "测试启动")
    @RequestMapping(value = "/testMethod",method = RequestMethod.GET)
    public String testMethod(String method) {
        logger.info("method"+method);
        return method;
    }

}

 

你可能感兴趣的:(-----【日志】)