gpt4 book ai didi

Logback.xml 配置

转载 作者:行者123 更新时间:2023-12-04 14:59:55 27 4
gpt4 key购买 nike

我正在尝试将粗壮配置为保存到文件中。
但是,它没有保存到文件中 - 你知道为什么吗?。
另外 - 我希望日志文件名可以在 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>

关于Logback.xml 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18204990/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com