Logback.xml配置

前端之家收集整理的这篇文章主要介绍了Logback.xml配置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试配置stout以保存到文件中.
但是,它没有保存到文件中 – 你知道为什么吗?
另外 – 我希望日志文件名可以在logback.xml中配置
像{LOG_FILE_NAME}这样来自cmd的东西 – 有可能吗?

这是我的logback.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!-- For assistance related to logback-translator or configuration  -->
<!-- files in general,please contact the logback user mailing list -->
<!-- at http://www.qos.ch/mailman/listinfo/logback-user             -->
<!--                                                                -->
<!-- For professional support please see                            -->
<!--    http://www.qos.ch/shop/products/professionalSupport         -->
<!--                                                                -->
<configuration>
  <appender name="defaultLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <!--See also http://logback.qos.ch/manual/appenders.html#RollingFileAppender-->
    <File>sarit_test.log</File>
    <encoder>
      <pattern>%d{dd MMM yyyy HH:mm:ss.SSS} [%t] %-5p %x %F:%L - %m</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"/>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <MaxFileSize>50000KB</MaxFileSize>
    </triggeringPolicy>
  </appender>
  <root level="INFO">
    <appender-ref ref="defaultLog"/>
  </root>
</configuration>
对于第一个答案,请在此处查看:
https://github.com/abdulwaheed18/Slf4jTutorial

第二个答案:您必须使用SIFT appender获取文件的系统参数.

<appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
    <!-- in the absence of the class attribute,it is assumed that the desired 
        discriminator type is ch.qos.logback.classic.sift.MDCBasedDiscriminator -->
    <discriminator>
        <key>FILE_NAME</key>
        <defaultValue>DEFAULT_FILE_NAME</defaultValue>
    </discriminator>
    <sift>
        <appender name="FILE-${FILE_NAME}"
            class="ch.qos.logback.core.rolling.RollingFileAppender">
            <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
                <evaluator> <!-- defaults to type ch.qos.logback.classic.boolex.JaninoEventEvaluator -->
                    <expression>return message.contains("Broken pipe");</expression>
                </evaluator>
                <OnMismatch>NEUTRAL</OnMismatch>
                <OnMatch>DENY</OnMatch>
            </filter>
            <File>${LOGDIR}/${FILE_NAME}.log</File>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <FileNamePattern>${LOGDIR}/${FILE_NAME}.%d{yyyy-MM-dd}.%i.log.gz
                </FileNamePattern>  <!-- keep 30 days' worth of history -->
                <MaxHistory>30</MaxHistory>
                <!-- Limit all logs size to 300MB -->
                <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <!-- or whenever the file size reaches 10MB -->
                    <maxFileSize>10MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
            </rollingPolicy>
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                <Pattern>%date [%thread] %-5level %logger{36} - %msg%n</Pattern>
            </encoder>
        </appender>
    </sift>
</appender>
原文链接:https://www.f2er.com/xml/292096.html

猜你在找的XML相关文章