1.修改pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependency>
<!--简化bean代码-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
2.自定义一个logback-spring.xml文件
路径:src\main\resources
以下是日志配置文件模板
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 属性文件:在properties/yml文件中找到对应的配置项 -->
<springProperty scope="context" name="logging.path" source="logging.path"/>
<contextName></contextName>
<appender>
//xxxx
</appender>
<logger>
//xxxx
</logger>
<root>
//xxxx
</root>
</configuration>
这里修改root level=debug加上新建一个console appender,level是debug,就能实现连框架的日志也能输出出来,特别是mybatis的sql语句也能实现输出
<!--输出到控制台-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>debug</level>
</filter>
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="CONSOLE" />
</root>
3.修改application.properties增加配置
logging.config=classpath:logback-spring.xml
4.创建controller,增加对应的方法输出日志
这里注意两点:
(1)@slf4j等价于private static Logger logger = LoggerFactory.getLogger(HelloWorldController.class);
不用写以上代码
(2)STS会不认识log这个变量,并且显示log cannot be resolved
这时候需要将logback的jar包引入到STS的安装目录,并修改加载配置文件
STS.ini,增加
-Xbootclasspath/a:lombok-1.18.12.jar
-javaagent:lombok-1.18.12.jar
@Slf4j
@Controller
public class HelloWorldController {
@RequestMapping("/log")
@ResponseBody
public String showLog(){
log.debug("debug级别的日志信息...");
log.info("info级别的日志信息...");
log.warn("warn级别的日志信息...");
log.error("error级别的日志信息...");
return "ok,"+log.getClass().getName();
}
}
结果截图
另外附上一个好用的文档对比工具网页,虽然beyond compare好用,但是要收费,所以只能将就使用。另外,tortoise SVN也有文档对比功能,但是只能对比txt,不能对比word,PDF
http://wenbenbijiao.renrensousuo.com/#diff