PricingBlogDocumentationDocsRegister

Connect your Log4j 2.x project to GlitchTip

Installation

Using Maven:

<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-log4j2</artifactId>
    <version>1.7.27</version>
</dependency>

Using Gradle:

compile 'io.sentry:sentry-log4j2:1.7.27'

Using SBT:

libraryDependencies += "io.sentry" % "sentry-log4j2" % "1.7.27"

For other dependency managers see the central Maven repository.

Usage

The following example configures a ConsoleAppender that logs to standard out at the INFO level and a SentryAppender that logs to the GlitchTip server at the WARN level. The ConsoleAppender is only provided as an example of a non-Sentry appender that is set to a different logging threshold, like one you may already have in your project.

Example configuration using the log4j2.xml format:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="warn" packages="org.apache.logging.log4j.core,io.sentry.log4j2">
    <appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>

        <Sentry name="Sentry" />
    </appenders>

    <loggers>
        <root level="INFO">
            <appender-ref ref="Console" />
            <!-- Note that the Sentry logging threshold is overridden to the WARN level -->
            <appender-ref ref="Sentry" level="WARN" />
        </root>
    </loggers>
</configuration>

Next, you’ll need to configure your DSN (client key) and optionally other values such as environment and release. [See the configuration page]({%- link _documentation/clients/java/config.md -%}#configuration) for ways you can do this.