Search code examples
loggingakkaakka-httpphantom-dsl

How to change log level in Akka-Http with Phantom


I have a new project with Akka-http 2.4.2 and com.websudos.phantom 1.22.0
All works fine but I don't know how to change the log level to INFO so the DEBUG logs of phantom like:

17:00:51.792 [cluster1-nio-worker-0] DEBUG com.datastax.driver.core.Connection - Connection[/192.168.120.24:9042-1, inFlight=0, closed=false] was inactive for 30 seconds, sending heartbeat 17:00:51.931

[cluster1-nio-worker-0] DEBUG com.datastax.driver.core.Connection - Connection[/192.168.120.24:9042-1, inFlight=0, closed=false] heartbeat query succeeded

and

17:07:27.387 [system-akka.actor.default-dispatcher-10] DEBUG com.websudos.phantom - Executing query: SELECT * FROM table1 WHERE user = '1_1003600499' LIMIT 1;

are ignore for console.

Can I put this configuration in the file application.conf?. If so, how?

RESOLUTION:
As @flavian answered (and with little modification)
1) Create a file logback.xml in the resources folder
2) Copy and pase the following configuration

<configuration scan="false">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -oijojj %msg%n</pattern>
    </encoder>
</appender>

<logger name="com.websudos.phantom" level="WARNING"/>

<root level="INFO">
    <appender-ref ref="STDOUT"/>
</root>

</configuration>

This will make the logs only show INFO level onwards on the console


Solution

  • Phantom offers a SLF4J/Logback compatible API, meaning all you need to do is to provide the right logback.xml configuration in the resources folder of the module you want to configure.

    Have a look at this.

    <configuration scan="false">
      <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
          <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
      </appender>
    
      <logger name="com.websudos.phantom" level="WARNING">
      </logger>
    
      <root level="INFO">
        <appender-ref ref="STDOUT" />
      </root>
    </configuration>