Home

Awesome

Logback appender for Report Portal

Maven Central CI Build codecov Join Slack chat! stackoverflow Build with Love License

The latest version: 5.2.2. Please use Maven Central link above to get the library.

Dependencies

To start using Report Portal log appending you need to include this library into your project dependencies according to your build system.

Maven

Add this section into <dependecies> section:


<dependency>
    <groupId>com.epam.reportportal</groupId>
    <artifactId>logger-java-logback</artifactId>
    <version>5.2.2</version>
    <scope>test</scope>
</dependency>

Gradle

Add this line into dependecies block:

testImplementation 'com.epam.reportportal:logger-java-logback:5.2.2'

Configuration

Add a report portal appender into logback.xml configuration file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="ReportPortalAppender" class="com.epam.reportportal.logback.appender.ReportPortalAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%t] %-5level - %msg%n</pattern>
        </encoder>
    </appender>
    <root>
        <appender-ref ref="ReportPortalAppender"/>
    </root>
</configuration>

Attaching files (Screenshots, videos, archives, reports etc.)

For logback it is possible to attach binary data to the file only by adding to the log message additional text information.

In this case a log message should have next format:

RP_MESSAGE#FILE#FILENAME#MESSAGE_TEST
RP_MESSAGE#BASE64#BASE_64_REPRESENTATION#MESSAGE_TEST

RP_MESSAGE - message header

FILE, BASE64 - attaching data representation type

FILENAME, BASE_64_REPRESENTATION - path to sending file/ base64 representation of sending data

MESSAGE_TEST - string log message

Example:

public class Test {
    private static final String JSON_FILE_PATH = "files/file.json";

    @Test
    public void logJsonBase64() {
        /* here we are logging some binary data as BASE64 string */
        LOGGER.info(
                "RP_MESSAGE#BASE64#{}#{}",
                BaseEncoding.base64().encode(Resources.asByteSource(Resources.getResource(JSON_FILE_PATH)).read()),
                "I'm logging content via BASE64"
        );
    }

    @Test
    public void logJsonFile() {
        /* here we are logging some binary data as file (useful for selenium) */
        File file = File.createTempFile("rp-test", ".json");
        Resources.asByteSource(Resources.getResource(JSON_FILE_PATH)).copyTo(Files.asByteSink(file));
        LOGGER.info("RP_MESSAGE#FILE#{}#{}", file.getAbsolutePath(), "I'm logging content via temp file");
    }
}

Grayscale images

There is a client parameter into reportportal.properties with boolean type value for screenshots sending in grayscale or color view. By default, it is set as true and all pictures for Report Portal will be in grayscale format.

reportportal.properties

rp.convertimage=true

Possible values: