{ "html": "
\n

Installation

\n

Using Maven:

\n
<dependency>\n    <groupId>io.sentry</groupId>\n    <artifactId>sentry-log4j</artifactId>\n    <version>1.6.3</version>\n</dependency>\n
\n
\n

Using Gradle:

\n
compile 'io.sentry:sentry-log4j:1.6.3'\n
\n
\n

Using SBT:

\n
libraryDependencies += "io.sentry" % "sentry-log4j" % "1.6.3"\n
\n
\n

For other dependency managers see the central Maven repository.

\n
\n\n\n
\n

Usage

\n

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

\n

Example configuration using the log4j.properties format:

\n
# Enable the Console and Sentry appenders\nlog4j.rootLogger=INFO, Console, Sentry\n\n# Configure the Console appender\nlog4j.appender.Console=org.apache.log4j.ConsoleAppender\nlog4j.appender.Console.layout=org.apache.log4j.PatternLayout\nlog4j.appender.Console.layout.ConversionPattern=%d{HH:mm:ss.SSS} [%t] %-5p: %m%n\n\n# Configure the Sentry appender, overriding the logging threshold to the WARN level\nlog4j.appender.Sentry=io.sentry.log4j.SentryAppender\nlog4j.appender.Sentry.threshold=WARN\n
\n
\n

Alternatively, using the log4j.xml format:

\n
<?xml version="1.0" encoding="UTF-8" ?>\n<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">\n<log4j:configuration debug="true"\n    xmlns:log4j='http://jakarta.apache.org/log4j/'>\n\n    <!-- Configure the Console appender -->\n    <appender name="Console" class="org.apache.log4j.ConsoleAppender">\n        <layout class="org.apache.log4j.PatternLayout">\n            <param name="ConversionPattern"\n                   value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />\n        </layout>\n    </appender>\n\n    <!-- Configure the Sentry appender, overriding the logging threshold to the WARN level -->\n    <appender name="Sentry" class="io.sentry.log4j.SentryAppender">\n        <!-- Override the Sentry handler log level to WARN -->\n        <filter class="org.apache.log4j.varia.LevelRangeFilter">\n            <param name="levelMin" value="WARN" />\n        </filter>\n    </appender>\n\n    <!-- Enable the Console and Sentry appenders, Console is provided as an example\n         of a non-Sentry logger that is set to a different logging threshold -->\n    <root level="INFO">\n        <appender-ref ref="Console" />\n        <appender-ref ref="Sentry" />\n    </root>\n</log4j:configuration>\n
\n
\n

Next, you’ll need to configure your DSN (client key) and optionally other values such as\nenvironment and release. See the configuration page for ways you can do this.

\n
\n", "link": "https://docs.getsentry.com/clients/java/modules/log4j/", "id": "java-log4j", "name": "Log4j 1.x" }