5

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.

Verhagen
  • 3,885
  • 26
  • 36
Paul
  • 78
  • 1
  • 3
  • 12

1 Answers1

3

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.

divanov
  • 6,173
  • 3
  • 32
  • 51
  • I don't use any logger, I mean there are none in my pom.xml (I use Maven for building). Serenity BDD is complex framework that handles logging, reports, libraries and other things for you. I know that it uses slf4j as logger. But i didn't figure out how to set the logger option so far. Do you think I can use your approach for slf4j logger? – Paul Oct 04 '15 at 14:14
  • slf4j is a logging facade, you still need a logger behind it. See updated answer. – divanov Oct 05 '15 at 09:01
  • I'll check it out tomorrow. Thank you. – Paul Oct 10 '15 at 12:11
  • the correct file is logback-test.xml not logback-tests.xml. see http://logback.qos.ch/manual/configuration.html – zwessels Jan 30 '16 at 06:41