When we installed Cassandra 3.11 I noticed that the default log location for the system.log file is

/opt/cass/apache-cassandra-3.11.3/logs

I want to change this so the file will be saved into /var/logs/cassandra

1. Shutdown Cassandra

ps -ef | grep java
kill -9 <PID>

As root
2. Create the directory

mkdir -p /var/log/cassandra/

3. Grant the cassandra user permissions

chown -R cassandra:cassandra /var/log/cassandra

4. Next go to $CASSANDRA_HOME/conf/logback.xml

5. Everywhere you see $CASSANDRA_HOME/conf/logs chance it to /var/log/cassandra

<appender name="SYSTEMLOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>INFO</level>
    </filter>
    <file>/var/log/cassandra/system.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <fileNamePattern>/var/log/cassandra/system.log.%i.zip</fileNamePattern>
      <minIndex>1</minIndex>
      <maxIndex>20</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <maxFileSize>20MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
      <pattern>%-5level [%thread] %date{ISO8601} %F:%L - %msg%n</pattern>
    </encoder>
  </appender>

<appender name="DEBUGLOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>/var/log/cassandra/debug.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <fileNamePattern>/var/log/cassandra/debug.log.%i.zip</fileNamePattern>
      <minIndex>1</minIndex>
      <maxIndex>20</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <maxFileSize>20MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
      <pattern>%-5level [%thread] %date{ISO8601} %F:%L - %msg%n</pattern>
    </encoder>
  </appender>

6. Start up Cassandra again and check to see if there is a log file in /var/log/cassandra

cassandra

Conclusion

There we have it, its very easy to change the location of the log file, shutdown, edit the config file, startup.

LEAVE A REPLY

Please enter your comment!
Please enter your name here