spring boot配置logback日志输出

文件目录结构:

spring boot配置logback日志输出_第1张图片

application.properties内容:

#默认使用application-local.properties,logback-my.xml中也将使用name="local"输出日志
spring.profiles.active=local

server.port=8090
#定义logback的名字,否则默认名字必须为:logback-spring.xml
logging.config=classpath:logback-my.xml


application-local.properties内容:(只是强制改变一下端口号)

server.port=8080

logback-my.xml:



	
	
	
	
	

    
        
            ${consoleLayoutPattern}
        
    

    
        ${LOG_HOME}/my_info.log
        
            ${LOG_HOME}/my_info.log.%d{yyyy-MM-dd}
            10
        
        
            ${fileLayoutPattern}
        
    

    
        ${LOG_HOME}/my_error.log
        
            ${LOG_HOME}/my_error.log.%d{yyyy-MM-dd}
            10
        
        
            ${fileLayoutPattern}
        
        
            error
            DENY
        
    

	
    
        
        
        	 
            
        
    

	
	
        
        
            
            
        
    
    
   	 
    
        
            
            
            
        
    



indexcontroller:

package com.my.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.my.bean.User;

@RestController
@RequestMapping("index")
public class IndexController {
	
	private static Logger log = LoggerFactory.getLogger(IndexController.class);
	
//	@Value(value = "${tanlei.secret}")
	private String secret;
	
	@RequestMapping
	public String index() {
		return "hello world";
	}

	@RequestMapping("get")
	public Map get(String name) {
		log.debug("xixi");
		log.info("哈哈哈");
		log.error("hehe");
		//System.out.println(secret);
		Map map = new HashMap();
		map.put("name", name);
		map.put("id", 1);
		return map;
	}
	
	@RequestMapping(value = "/get/{id}/{name}")
	public User getUser(@PathVariable int id, @PathVariable String name) {
		User user = new User();
		user.setId(id);
		user.setName(name);
		user.setDate(new Date());
		return user;
	}
	
}

启动类:SrpingBootDemo1Application.java

@SpringBootApplication
public class SrpingBootDemo1Application {
	
	public static void main(String[] args) {
		SpringApplication.run(SrpingBootDemo1Application.class, args);
	}
}


pom.xml



	4.0.0

	com.my
	bootweb
	0.0.1-SNAPSHOT
	war

	
		org.springframework.boot
		spring-boot-starter-parent
		1.4.0.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	

		
			org.springframework.boot
			spring-boot-starter-web
		
		
			org.springframework.boot
			spring-boot-starter-tomcat
			provided
		
		
			org.apache.tomcat.embed
			tomcat-embed-jasper
			provided
		
		
			javax.servlet
			jstl
		

		
			org.webjars
			jquery
			2.1.4
		

		
			org.springframework.boot
			spring-boot-devtools
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
				
				
					root
				
			
		
	






你可能感兴趣的:(spring,boot)