gpt4 book ai didi

java - 不同类的不同日志级别

转载 作者:行者123 更新时间:2023-11-30 08:31:33 25 4
gpt4 key购买 nike

下面,我有一个全局应用的 logback 配置。

除了一个类,我想全局设置日志记录级别 ERROR。对于一个特定的类,我想将日志记录级别设置为 INFO。我该怎么做?

<configuration scan="truef" scanPeriod="30 seconds">

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="com.foo.web.online.util.log.LogMaskingPatternLayout">

<pattern>[START] Date: %d{yyyy-MM-dd} | Time: %d{HH:mm:ss.SSS} | Level: %-5level | Logger: %logger{5} | Marker: %marker | CIP: %X{clientIp} | UserAgent: %X{userAgent} | Website: %X{website} | SID: %X{sessionId} | RID: %X{requestId} | CID: %X{conversationId} | TID: %X{transactionId} | App: %X{app} | SubApp: %X{subApp} | Msg: %msg [END] %n</pattern>
</layout>
</encoder>
</appender>

<appender name="SIFT_INFO" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator class="ch.qos.logback.classic.sift.JNDIBasedContextDiscriminator">
<defaultValue>unknown</defaultValue>
</discriminator>
<sift>
<appender name="FILE-${contextName}" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/opt/local/logs/online/${contextName}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/opt/local/logs/online/${contextName}-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="com.foo.web.online.util.log.LogMaskingPatternLayout">
<pattern>[START] Date: %d{yyyy-MM-dd} | Time: %d{HH:mm:ss.SSS} | Level: %-5level | Logger: %logger{5} | Marker: %marker | CIP: %X{clientIp} | UserAgent: %X{userAgent} | Website: %X{website} | SID: %X{sessionId} | RID: %X{requestId} | App: %X{app} | SubApp: %X{subApp} | Page: %X{page} | Device: %X{device} | Browser: %X{browser} | Lang: %X{language} | IPCountry: %X{geoIpCountry} | IPCity: %X{geoIpCity} | ErrCode: %X{errorCode} | Msg: %msg [END] %n</pattern>
</layout>
</encoder>
</appender>
</sift>
</appender>


<logger name="com.foo" level="INFO">
<appender-ref ref="SIFT_INFO" />
<!-- <appender-ref ref="STDOUT" /> -->
</logger>

<logger name="org.hibernate.type" level="INFO" />
<logger name="org.hibernate" level="INFO" />


</configuration>

最佳答案

您可以像这样使用根记录器:

<root>
<level value="ERROR"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="SIFT_INFO"/>
</root>
<logger name="org.mycompany.MyClass">
<level value="INFO"/>
</logger>

关于java - 不同类的不同日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40586985/

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