gpt4 book ai didi

java - Cassandra Java 驱动程序日志记录

转载 作者:行者123 更新时间:2023-12-01 10:09:49 25 4
gpt4 key购买 nike

我们使用 logback 作为我们的 java 项目的日志框架...logback 配置如下

<configuration debug="true">
<property name="LOG_HOME" value="/etc/report-synchronizer" />
<appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<key>modulename</key>
<defaultValue>unknown</defaultValue>
</discriminator>

<sift>
<appender name="FILE-${modulename}"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_HOME}/${modulename}-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 5MB -->
<maxFileSize>5MB</maxFileSize>
<!-- Number of days for which the files will be kept -->
<maxHistory>10</maxHistory>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %level %mdc %logger{35} - %msg%n</pattern>
</layout>
</appender>
</sift>
</appender>

<root level="DEBUG">
<appender-ref ref="SIFT" />
</root>
</configuration>

我们在项目中使用java cassandra驱动程序。 cassandra 驱动程序生成的所有日志都与我们的应用程序日志混合在一起。有没有办法将 cassandra 驱动程序日志分离到单独的文件

提前致谢

最佳答案

声明一个名为 com.datastax.driver 的记录器、一个专用附加程序,并将可加性设置为 false。这样您就可以将驱动程序日志限制到其附加程序。

以下示例将为您提供一个良好的开端:

<logger name="com.datastax.driver" level="INFO" additivity="false">
<appender-ref ref="DRIVER"/>
</logger>

<appender name="DRIVER" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${LOG_HOME}/${modulename}-driver.log</file>

<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %level %mdc %logger{35} - %msg%n</pattern>
</layout>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_HOME}/${modulename}-driver-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 5MB -->
<maxFileSize>5MB</maxFileSize>
<!-- Number of days for which the files will be kept -->
<maxHistory>10</maxHistory>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>

</appender>

关于java - Cassandra Java 驱动程序日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36197007/

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