pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
log4j.properties
log4j.rootLogger = INFO, console
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold = DEBUG
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = D://log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = WARN
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
application.properties
logging:
config: src/main/resources/log4j.properties
.java
public class ClientStarter {
private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(ClientStarter.class);
public static void main(String[] args) {
ClientStarter.class.getClassLoader().getResourceAsStream("log4j.properties");
log.debug("haha, this is log4j debug");
log.info("haha, this is log4j info");
log.warn("haha, this is log4j warn");
log.error("haha, this is log4j error");
SpringApplication.run(ClientStarter.class);
}
https://blog.csdn.net/sinat_30185177/article/details/73550377