Skip to content

Commit

Permalink
修改配置文件为logback-spring
Browse files Browse the repository at this point in the history
  • Loading branch information
mason committed Nov 28, 2019
1 parent e4e0c61 commit 668bd3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class UserService {
*/
public User getUserById(long id) {
log.debug("get user by id:{}", id);
//测试输出error日志
if (id == 10L) {
log.error("error id:{}", id);
return null;
Expand All @@ -53,6 +54,12 @@ public List<User> getUsers() {
}

log.info("return users:{}", users);
//测试输出
log.trace("------log trace");
log.debug("------log debug");
log.info("------log info");
log.warn("------log warn");
log.error("------log error");
return users;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration scan="true" scanPeriod="1 seconds">
<!--日志文档前缀,即应用名称 -->
<!--日志文件前缀,即应用名称 -->
<property name="logfile.prefix" value="logback-demo"/>
<!--日志路径,可写相对路径,也可写绝对路径 -->
<property name="log.path" value="logs"/>
<!-- 日志输出格式 -->
<property name="log.pattern"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5level [%15thread] [%40logger{40}] [%10method,%line] : %msg%n"/>
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5level [%15thread] %40.40logger{40} [%10method,%line] : %msg%n"/>

<!-- 控制台输出日志 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
Expand Down Expand Up @@ -84,6 +84,12 @@
</layout>
</appender>

<!-- 继承上级root日志级别,默认向上级传递日志内容,本身不输出 -->
<!--<logger name="me.mason.demo.simplelogback.service"/>-->
<!-- 日志级别,不向上级传递日志内容,日志按appender-ref输出 -->
<logger name="me.mason.demo.simplelogback.service.UserService" level="WARN" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>
<!-- 日志输出 -->
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
Expand Down

0 comments on commit 668bd3c

Please sign in to comment.