Search code examples
logginglog4jthucydidesserenity-bdd

How can I change serenity-bdd log settings


I use Serenity BDD for test automation on my project, IntelliJ IDEA as IDE. I would like to change format and debug level of the logs I can see everytime I run tests.

For example, I want to see logs only from [main] thread:

[main] INFO net.thucydides.core.reports.junit.JUnitXMLOutcomeReport
[pool-3-thread-1] INFO net.thucydides.core.reports.ReportService - 

I know how to do it for logback, but I can't find any info on how and where one should change log settings for Serenity.


Solution

  • The output is produced by code you are testing not by Serenity BDD. So in order to modify output you should be changing logging properties of the logger you use.

    slf4j is a logging facade, it finds proper logger and redirect output to it. So you need to add a logger to your application and then configure it the way you like.

    For example, adding logback to your configuration.

    Add it logback as dependency to a project

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.3</version>
    </dependency>
    

    add src/test/resources/logback-test.xml to guide what logback should be logging.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>
                    %-5level %logger{36} - %msg%n
                </Pattern>
            </layout>
        </appender>
    
        <!-- set DEBUG logging level for a package -->
        <logger name="com.my.package" level="debug">
    
        <!-- log warnings and errors by default -->
        <root level="warn">
            <appender-ref ref="STDOUT" />
        </root>
    
    </configuration>
    

    This configuration will log warnings and error to console. And will log also debug and info messages for package com.my.package.

    If you don't like logback, use log4j2 or any other logger of your choice.