将logback.xml转换为application.properties

k4emjkb1  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(246)

如何将logback.xml文件转换为属性?
例如,有这样一个配置文件或我在下面附上的代码。我需要在application.properties中编写类似的属性
是否有此类配置的示例?用这个问题的例子正确吗?

<configuration>
    <timestamp key="today" datePattern="yyyy-MM-dd"/>
    <property name="LOG_HOME" value="log"/>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <Pattern>
                %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
            </Pattern>
        </encoder>
    </appender>

    <appender name="FILE-AUDIT" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/board_of_ads-${today}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>${LOG_HOME}/archive/board_of_ads-log_%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
            <!-- each file should be at most 20MB, keep 30 days worth of history, but at most 1GB -->
            <maxFileSize>20MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>1GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <Pattern>
                %d{DEFAULT} %-5level [%t] %c: %msg%n
            </Pattern>
        </encoder>
    </appender>

    <appender name="AuthController-Audit"
              class="ch.qos.logback.core.FileAppender">
        <file>${SIMPLE_CONTROLLER_HOME}/auth-controller/AuthController-log_${today}.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>
                %d{DEFAULT} %level - %msg%n
            </Pattern>
        </encoder>
    </appender>

    <logger name="com.board_of_ads" level="INFO" additivity="false">
        <appender-ref ref="FILE-AUDIT"/>
        <appender-ref ref="STDOUT"/>
    </logger>
    <!--    Controllers loggers setup-->
    <logger name="com.board_of_ads.controllers.simple.AuthController" level="INFO" additivity="true">
        <appender-ref ref="AuthController-Audit"/>
    </logger>

    <logger name="com.board_of_ads.controllers.rest.NotificationRestController" level="DEBUG" additivity="true">
        <appender-ref ref="NotificationRestController-Audit"/>
        <appender-ref ref="STDOUT"/>
    </logger>
</configuration>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题