简体   繁体   English

Cassandra Java驱动程序日志记录

[英]Cassandra Java driver logging

We are using logback as the logging framework for our java project... The logback configuration is as given below 我们正在使用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>

We are using java cassandra driver in the project. 我们在项目中使用java cassandra驱动程序。 All the logs generated by the cassandra driver are getting mixed up with our application logs. cassandra驱动程序生成的所有日志都与我们的应用程序日志混在一起。 Is there any way to separate the cassandra driver logs to a separate file 有什么办法可以将cassandra驱动程序日志分离到单独的文件中

Thanks in advance 提前致谢

Declare a logger with name com.datastax.driver , a dedicated appender, and additivity set to false . 声明名称为com.datastax.driver的记录器(专用的附加程序),并将可加性设置为false This way you will confine the driver logs to its appender. 这样,您可以将驱动程序日志限制到其附加程序。

The following example should give you a good start: 以下示例应为您提供一个良好的开端:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM