title: How to customize logging levels for Cassandra and Spark
body: <p>I'm trying to customize logging coming from com.datastax.driver for Cassandra and Apache Spark. These libraries output debug logs to console, and I would like to change it to error level. I tried to use log4j with .properties and .xml configuration and slf4j with .xml configuration. However, I  could not override configuration from these libraries. I found many discussions and I tried everything many different options. My configuration looks like:</p>
  
  <p><strong>log4j.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" &gt;
  &lt;log4j:configuration  xmlns:log4j="http://jakarta.apache.org/log4j/"  debug="false"&gt;
  &lt;appender name="console" class="org.apache.log4j.ConsoleAppender"&gt;
      &lt;layout class="org.apache.log4j.PatternLayout"&gt;
          &lt;param name="ConversionPattern" value="%5p\t[%d] [%t] %c{3} (%F:%L)     \t%m%n" /&gt;
      &lt;/layout&gt;
  &lt;/appender&gt;
  &lt;category name="c.d.driver"&gt;
      &lt;level value="ERROR" /&gt;
      &lt;appender-ref ref="console" /&gt;
  &lt;/category&gt;
  &lt;logger name="com.datastax.driver"&gt;
      &lt;level value="fatal" /&gt;
  &lt;!--        &lt;appender-ref ref="console" /&gt; --&gt;
  &lt;/logger&gt;
  &lt;logger name="org.apache.spark"&gt;
      &lt;level value="ERROR" /&gt;
      &lt;appender-ref ref="console" /&gt;
  &lt;/logger&gt;
  &lt;logger name="o.a.s.s"&gt;
      &lt;priority value="off" /&gt;
  &lt;!--    &lt;appender-ref ref="console" /&gt; --&gt;
  &lt;/logger&gt;
  &lt;root&gt;
      &lt;level value="INFO" /&gt;
      &lt;appender-ref ref="console" /&gt;
  &lt;/root&gt;
  &lt;/log4j:configuration&gt;
  </code></pre>
  
  <p>Is there any solution for this problem?</p>
  
  <p><strong>UPDATE</strong>
  I reached what I wanted to have, but I'm really confused why this happens. 
  First I tried to use log4j in my application with previously described configuration and it didn't work. Then I switched to slf4j with configuration:</p>
  
  <p><strong>logback.xml</strong></p>
  
  <pre><code>&lt;configuration debug="true"&gt; 
   &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt; 
    &lt;encoder&gt;
    &lt;pattern&gt;%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n&lt;/pattern&gt;
    &lt;/encoder&gt;
   &lt;/appender&gt;
   &lt;logger name="org.apache.spark" level="error"&gt;
      &lt;appender-ref ref="STDOUT" /&gt;
   &lt;/logger&gt;
   &lt;root level="ERROR"&gt;
     &lt;appender-ref ref="STDOUT" /&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p></p>
  
  <p>This didn't work as well. As both Spark and Datastax driver are using log4j, I got back to Log4j again, so I removed slf4j loggers from the code, but left it's configuration and maven dependency. When I started with log4j again, in my code log4j.xml configuration is initialized using DOMConfigurator. However, logback.xml is loaded as well, without being explicitly loaded in the code. The loggers for Spark and Datastax specified in this configuration are applied in this way. I don't understand why it didn't work for external libraries when I loaded it using JoranConfigurator. It only affected my code, but not these libraries.
  So, at the end my solution that works for me looks like:</p>
  
  <ul>
  <li>log4j configuration (log4j.xml) loaded from the application and applied to my application</li>
  <li>slf4j configuration (logback.xml) which is not loaded specifically in my application applies rules to the Apache Spark and Datastax driver for Cassandra.</li>
  </ul>
  
  <p>It would be great if somebody could explain why this happened.</p>