zoukankan      html  css  js  c++  java
  • SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active(转)

    趁今天有时间整理了一下

    启动命令为

    //开发环境

    java -jar app.jar --spring.profiles.active=dev--server.port=8060

    //测试环境

    java -jar app.jar --spring.profiles.active=qa --server.port=8060

    //生产环境

    java -jar app.jar --spring.profiles.active=prod --server.port=8060

    废话少说,直接上代码

    application.yml,打包为jar的时候主要把spring.profile.active注释掉.否则 命令行参数 --spring.profiles.active可能不生效,不知何解

    复制代码
    spring:
      profiles:
        #指定读取配置文件:dev(开发环境),prod(生产环境),qa(测试环境)
        active: qa
    

    日志

    logging:
    config: classpath:logback-${spring.profiles.active}.xml

    复制代码

     logback-dev.xml

    复制代码
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration debug="true">
    <contextName>logback</contextName>
    <property name="log.path" value="lzw/logback.log" />
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">appender </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="console"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="ch.qos.logback.core.ConsoleAppender"</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">filter </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="ch.qos.logback.classic.filter.ThresholdFilter"</span><span style="color: #0000ff">&gt;</span></br>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">level</span><span style="color: #0000ff">&gt;</span>debug<span style="color: #0000ff">&lt;/</span><span style="color: #800000">level</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">filter</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
            </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">appender</span><span style="color: #0000ff">&gt;</span></br>
    
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">appender </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="file"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="ch.qos.logback.core.rolling.RollingFileAppender"</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">file</span><span style="color: #0000ff">&gt;</span>${log.path}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">file</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">rollingPolicy </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"</span><span style="color: #0000ff">&gt;</span></br>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">fileNamePattern</span><span style="color: #0000ff">&gt;</span>${log.path}.%d{yyyy-MM-dd}.zip<span style="color: #0000ff">&lt;/</span><span style="color: #800000">fileNamePattern</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">rollingPolicy</span><span style="color: #0000ff">&gt;</span></br></br>
    
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">%date %level [%thread] %logger{36} [%file : %line] %msg%n
            </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">appender</span><span style="color: #0000ff">&gt;</span></br></br>
    
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">root </span><span style="color: #ff0000">level</span><span style="color: #0000ff">="warn"</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">appender-ref </span><span style="color: #ff0000">ref</span><span style="color: #0000ff">="console"</span> <span style="color: #0000ff">/&gt;</span></br>
        <span style="color: #008000">&lt;!--</span><span style="color: #008000">&lt;appender-ref ref="file" /&gt;</span><span style="color: #008000">--&gt;</span></br>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">root</span><span style="color: #0000ff">&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.springframework.scheduling"</span><span style="color: #ff0000">  level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.catalina.util.LifecycleBase"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.coyote.http11.Http11NioProtocol"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.tomcat.util.net.NioSelectorPool"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.springframework"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="debug"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="com.lzw"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="debug"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.mybatis"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="debug"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.Connection"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.Statement"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.PreparedStatement"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.ResultSet"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    

    </configuration>

    复制代码

    logback-qa.xml

    复制代码
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <configuration debug="true">
        <contextName>logback</contextName>

    <span style="color: #0000ff">&lt;</span><span style="color: #800000">property </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="log.path"</span><span style="color: #ff0000"> value</span><span style="color: #0000ff">="lzw/logback.log"</span> <span style="color: #0000ff">/&gt;</span></br></br>
    
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">appender </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="console"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="ch.qos.logback.core.ConsoleAppender"</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">filter </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="ch.qos.logback.classic.filter.ThresholdFilter"</span><span style="color: #0000ff">&gt;</span></br>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">level</span><span style="color: #0000ff">&gt;</span>debug<span style="color: #0000ff">&lt;/</span><span style="color: #800000">level</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">filter</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
            </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">appender</span><span style="color: #0000ff">&gt;</span></br></br>
    
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">appender </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="file"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="ch.qos.logback.core.rolling.RollingFileAppender"</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">file</span><span style="color: #0000ff">&gt;</span>${log.path}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">file</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">rollingPolicy </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"</span><span style="color: #0000ff">&gt;</span></br>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">fileNamePattern</span><span style="color: #0000ff">&gt;</span>${log.path}.%d{yyyy-MM-dd}.zip<span style="color: #0000ff">&lt;/</span><span style="color: #800000">fileNamePattern</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">rollingPolicy</span><span style="color: #0000ff">&gt;</span></br></br>
    
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">%date %level [%thread] %logger{36} [%file : %line] %msg%n
            </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">appender</span><span style="color: #0000ff">&gt;</span></br></br>
    
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">root </span><span style="color: #ff0000">level</span><span style="color: #0000ff">="warn"</span><span style="color: #0000ff">&gt;</span></br>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">appender-ref </span><span style="color: #ff0000">ref</span><span style="color: #0000ff">="file"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">root</span><span style="color: #0000ff">&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.springframework.scheduling"</span><span style="color: #ff0000">  level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="com.lzw"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.catalina.util.LifecycleBase"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.coyote.http11.Http11NioProtocol"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.tomcat.util.net.NioSelectorPool"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.springframework"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.mybatis"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.Connection"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.Statement"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.PreparedStatement"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.ResultSet"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
    

    </configuration>

    复制代码
  • 相关阅读:
    ionic 白名单
    简单的apk Ionic
    Ionic 小节
    Ionic学习笔记四 一些问题处理
    Android Platform Guide
    Android各个版本 版本号对应关系表
    JBPM4.4_管理流程定义
    JBPM4.4_核心概念与相关API
    工作流JBPM_day01:3-使用JBPM的API添加与执行流程
    工作流JBPM_day01:2-HelloWorld
  • 原文地址:https://www.cnblogs.com/jpfss/p/8341915.html
Copyright © 2011-2022 走看看