Cassandra Java驱动程序日志记录

时间:2016-03-24 09:37:55

标签: java cassandra logback

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

<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驱动程序日志分成单独的文件

提前致谢

1 个答案:

答案 0 :(得分:1)

声明一个名为com.datastax.driver的记录器,一个专用的appender,以及设置为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>