Spring Boot入门教程:五、spring boot 2.0 日志配置

        spring boot的web模块已经引入了日志相关的依赖,所以我们只需要在application.properties文件中配置相关信息就可以了,日志及其他常用配置如下:

#应用名称
spring.application.name=boot-demo

#端口号
server.port=8000
#超时时间
server.connection-timeout = 60000

#tomcat
server.tomcat.max-threads = 1024
server.tomcat.min-spare-threads = 32
server.tomcat.background-processor-delay=30
server.tomcat.uri-encoding = UTF-8
server.tomcat.basedir=${user.dir}/tmp

#日志
#logging.path=${user.dir}/logs
logging.path=/root/log
logging.file=${logging.path}/boot-demo.log
logging.level.root=info
logging.level.com.ldy = info

#设置Date日期格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

编写测试类

package com.ldy.bootv2.demo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(tags = "测试接口-API")
public class HelloController {
	
	private static Logger logger = LoggerFactory.getLogger(HelloController.class);

	@GetMapping("/hello")
	@ApiOperation("hello的测试接口")
	@ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String")
	public String index(@RequestParam(required = true) final String name) {
		logger.info("您调用了hello 接口");
		return "hello " + name;
	}

	@PostMapping("/sum")
	@ApiOperation("两整数求和接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "a", value = "参数a", required = true, dataType = "int"),
			@ApiImplicitParam(name = "b", value = "参数b", required = true, dataType = "int") })
	public String sum(@RequestParam(required = true) final Integer a, @RequestParam(required = true) final Integer b) {
		logger.info("您调用了sum 接口");
		int sum = a + b;
		return "a + b = " + sum;
	}

}

 

你可能感兴趣的:(spring,boot,spring,boot,2.0,入门实战教程)