spring-boot的日志管理(logback)之生产测试环境的切换

application.properties(当前用的是生产环境)

#spring.profiles.active=dev
spring.profiles.active=prod

application-dev.properties

server.port=8089
logging.file=application-dev.log
#logging.level.zn.controller= debug 
#logging.level.root=WARN

application-prod.properties

server.port=8090
logging.file=application-prod.log
#logging.level.zn.controller= WARN 

logback-spring.xml



	 

	
	
		  
			
        	  
        	
        	  
    	  
	
	
	
	
		
		  
        	  
        	  
    	  
    	
		
	
  

TestController.java
package zn.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
	 private final Logger logger = LoggerFactory.getLogger(this.getClass());  
     
	    @RequestMapping("log")  
	    public Object writeLog()  
	    {  
	        logger.debug("This is a debug message");  
	        logger.info("This is an info message");  
	        logger.warn("This is a warn message");  
	        logger.error("This is an error message");  
	        return "OK";  
	    }  
}
TestController1.java
package zn.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController1 {
	 private final Logger logger = LoggerFactory.getLogger(this.getClass());  
     
	    @RequestMapping("log1")  
	    public Object writeLog()  
	    {  
	        logger.debug("This is a debug message");  
	        logger.info("This is an info message");  
	        logger.warn("This is a warn message");  
	        logger.error("This is an error message");  
	        return "OK";  
	    }  
}

启动项目一次访问http://localhost:8090/log,http://localhost:8090/log1



日志文件:




项目目录结构:

spring-boot的日志管理(logback)之生产测试环境的切换_第1张图片

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