Search code examples
javaspringlogbacksentry

Getting error on adding encoder to sentry appender


Trying to integrate sentry(logback) in a spring application but getting this error

java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:18 - no applicable action for [encoder], current ElementPath  is [[configuration][appender][encoder]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@33:22 - no applicable action for [pattern], current ElementPath  is [[configuration][appender][encoder][pattern]]

The logback.xml file looks like this. I have taken the sentry code from there official documentation.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- <include resource="org/springframework/boot/logging/logback/defaults.xml"/><include resource="org/springframework/boot/logging/logback/console-appender.xml"/> -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] [%file:%line] - %msg %n</pattern>
        </encoder>
    </appender>
<appender name="Sentry" class="io.sentry.logback.SentryAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <!-- Optionally add an encoder -->
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%level] from %logger in %thread : %msg %n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="CONSOLE" />
    </root>

    <root level="ERROR">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="Sentry"/>
    </root>
</configuration>

What am I doing wrong here?


Solution

  • There is no support for configuring encoder for SentryAppender. All the information like level, logger, thread and more, are sent to Sentry together with the log message in a structured way - there is no need to configure an encoder.

    When using Sentry Spring Boot Starter, SentryAppender can be auto-configured so that you don't need to add it to logback.xml (see docs)

    If there is a use case that we missed and you believe encoder should be configurable, please raise an issue.