1. 日志框架的选择:(这两个框架,springBoot已经整合,无需引入jar包)
2. 在resources目录下配置logback-spring.xml
%d - %msg%n ERROR DENY ACCEPT %msg%n F:sellLoginfo.%d.log ERROR %msg%n F:sellLogerror.%d.log
3. 在springBoot启动类添加日志相应的对象(本例使用了junit测试,与在启动类配置一样)
package com.yzy.sell;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith (SpringRunner.class)
@SpringBootTest
public class SellApplicationTests {
private final Logger log= LoggerFactory.getLogger(SellApplicationTests.class);
@Test
public void test1() {
String name = "yzy";
String password = "123456";
log.debug("debug...");
log.info("name: " + name + " ,password: " + password);
log.info("name: {}, password: {}", name, password);
log.error("error...");
log.warn("warn...");
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



