1:在resources目录下面创建logback.xml配置文件

<?xml version="1.0"?>
<configuration>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender> <!-- 文件输出-->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>G:/tmp/logs/ydbg.%d{yyyyMMdd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">>
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender> <!-- 日志级别 -->
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>

2:TestCtrl.java测试

package com.example.springbootlogback.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import java.util.HashMap;
import java.util.Map; /**
* Created by yan on 2017/8/7.
*/
@RestController
@RequestMapping(
value = "/test",
produces = "application/json;charset=utf-8",
headers = "Accept=application/json")
public class TestCtrl {
private static final Logger log = LoggerFactory.getLogger(TestCtrl.class); @RequestMapping(
value = "/{key}/{value}",
method = RequestMethod.GET
)
public Map<String,String> test(@PathVariable String key, @PathVariable String value){
Map<String,String> map = new HashMap<String, String>();
map.put(key, value); log.error("key:"+key+",value:"+value); return map;
}
}

3:build.gradle

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test') // https://mvnrepository.com/artifact/ch.qos.logback/logback-core
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3' }

最新文章

  1. 3-EM的安装和使用
  2. 解决svn uuid变更问题
  3. 解析Myeclipse项目下的.classpath文件
  4. MySQL自带information_schema数据库使用
  5. Python初学者笔记:打印出斐波那契数列的前10项
  6. 【BZOJ】【4027】【HEOI2015】兔子与樱花
  7. PostgreSql与sqlserver对比杂记
  8. 字符编解码的故事 字符集 GBK GB2312 GB18030 Unicode 的由来和区别
  9. 关于EF中ApplyCurrentValues和ApplyOriginalValues区别
  10. C++中的类和对象(一)
  11. 纯CSS滑动效果
  12. 原生JS的DOM节点操作
  13. Bootstrap 3 与 Foundation 5
  14. HDU 3342 Legal or Not (图是否有环)【拓扑排序】
  15. Python打包方法——Pyinstaller
  16. 第三部分:Android 应用程序接口指南---第二节:UI---第五章 设置(Settings)
  17. Python3 自定义请求头消息headers
  18. 【Spring学习笔记-MVC-7】Spring MVC模型对象-模型属性讲解
  19. 在PHP中使用MySQL Mysqli操作数据库 ,以及类操作方法
  20. thinkphp5.0动态配置

热门文章

  1. C#编程(二十五)----------接口
  2. python测试开发django-16.JsonResponse返回中文编码问题
  3. 详细解释如何通过Android自带的方式来实现图片的裁剪——原理分析+解决方案
  4. [Web 前端] 解决因inline-block元素导致的空白间距和元素下沉
  5. Generalized normal distribution and Skew normal distribution
  6. [转]PHP traits
  7. shell单引号与变量、双引号与变量、如何在多重引号里面取到shell变量的值?
  8. 【ContestHunter】【弱省胡策】【Round6】
  9. Windows7安装CodeTyphon
  10. Pytorch多GPU并行处理