一、配置日志文件名
logging.file.name=myapplication.log
二、在resources下创建logback-spring.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-
${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
logback普通的配置(logback-spring.xml)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name ="cn.edu.tju" level="TRACE"/>
</configuration>
测试类:
package cn.edu.tju;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.annotation.PostConstruct;
@SpringBootApplication
public class Start {
private static Logger logger = LoggerFactory.getLogger(Start.class);
public static void main(String[] args) {
SpringApplication.run(Start.class,args);
}
@PostConstruct
public void log(){
logger.trace("my trace");
logger.debug("my debug");
logger.info("my info");
logger.error("my error");
}
}
运行效果
###############################################################
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name ="cn.edu.tju" level="TRACE"/>
<springProfile name="prod">
<logger name ="cn.edu.tju" level="ERROR"/>
</springProfile>
<springProfile name="dev">
<logger name ="cn.edu.tju" level="DEBUG"/>
</springProfile>
</configuration>