spring-boot的日志管理(logback)之生产测试环境的切换
2017-04-10 20:23
786 查看
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
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<!-- 测试环境 -->
<springProfile name="dev">
<logger name="zn" level="INFO" additivity="false">
<!-- 控制台打印-->
<appender-ref ref="CONSOLE"/>
<!-- 存储日式文件 -->
<appender-ref ref="FILE"/>
</logger>
</springProfile>
<!-- 生产环境 -->
<springProfile name="prod">
<!-- 可以指定那个包下的日志级别 -->
<logger name="zn.controller" level="WARN" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<!-- 默认的级别,除去上面配置的 -->
<root level="ERROR"></root>
</springProfile>
</configuration>
TestController.java
启动项目一次访问http://localhost:8090/log,http://localhost:8090/log1
日志文件:
项目目录结构:
#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
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<!-- 测试环境 -->
<springProfile name="dev">
<logger name="zn" level="INFO" additivity="false">
<!-- 控制台打印-->
<appender-ref ref="CONSOLE"/>
<!-- 存储日式文件 -->
<appender-ref ref="FILE"/>
</logger>
</springProfile>
<!-- 生产环境 -->
<springProfile name="prod">
<!-- 可以指定那个包下的日志级别 -->
<logger name="zn.controller" level="WARN" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<!-- 默认的级别,除去上面配置的 -->
<root level="ERROR"></root>
</springProfile>
</configuration>
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
日志文件:
项目目录结构:
相关文章推荐
- shell 管理SpringBoot 生产环境服务 (备份日志)
- (33)Spring Boot 监控和管理生产环境【从零开始学Spring Boot】
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- shell 管理SpringBoot 生产环境服务 2
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 监控和管理生产环境spring boot actuator
- Spring Boot24 之 监控和管理生产环境
- SpringBoot日志logback-spring.xml分环境
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 监控和管理生产环境spring boot actuator
- SpringBoot(六)开发环境/测试环境和生产环境
- 33. Spring Boot 监控和管理生产环境【从零开始学Spring Boot】
- (33)Spring Boot 监控和管理生产环境【从零开始学Spring Boot】
- springboot【17】日志管理之logback
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Spring.profile实现开发、测试和生产环境的配置和切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换