简体   繁体   中英

Cassandra Java driver logging

We are using logback as the logging framework for our java project... The logback configuration is as given below

<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. All the logs generated by the cassandra driver are getting mixed up with our application logs. Is there any way to separate the cassandra driver logs to a separate file

Thanks in advance

Declare a logger with name com.datastax.driver , a dedicated appender, and additivity set to 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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