Raven-Java provides log4j support for Raven. It provides an Appender for log4j to send the logged events to Sentry.

The project can be found on github: raven-java/raven-log4j


If you want to use Maven you can install Raven-Log4j as dependency:


If you manually want to manage your dependencies:


The following configuration (logging.properties) gets you started for logging with log4j and Sentry:

log4j.rootLogger=WARN, SentryAppender
# Optional, allows to select the ravenFactory

Alternatively in the log4j.xml file set:

<appender name="sentry" class="com.getsentry.raven.log4j.SentryAppender">
  <param name="dsn" value="___DSN___"/>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="levelMin" value="WARN"/>

It’s possible to add extra details to events captured by the Log4j module thanks to both the MDC and the NDC systems provided by Log4j are usable, allowing to attach extras information to the event.

Practical Example

import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.apache.log4j.NDC;

public class MyClass {
    private static final Logger logger = Logger.getLogger(MyClass.class);

    void logSimpleMessage() {
        // This adds a simple message to the logs
        logger.info("This is a test");

    void logWithExtras() {
        // MDC extras
        MDC.put("extra_key", "extra_value");
        // NDC extras are sent under 'log4J-NDC'
        // This adds a message with extras to the logs
        logger.info("This is a test");

    void logException() {
        try {
        } catch (Exception e) {
            // This adds an exception to the logs
            logger.error("Exception caught", e);

    void unsafeMethod() {
        throw new UnsupportedOperationException("You shouldn't call that");

Mapped Tags

By default all MDC parameters are sent under the Additional Data Tab. By specify the extraTags parameter in your configuration file. You can specify MDC keys to send as tags instead of including them in Additional Data. This allows them to be filtered within Sentry.

    void logWithExtras() {
        // MDC extras
        MDC.put("Environment", "Development");
        MDC.put("OS", "Linux");

        // This adds a message with extras and MDC keys declared in extraTags as tags to Sentry
        logger.info("This is a test");

Asynchronous Logging

It is not recommended to attempt to set up SentryAppender within an AsyncAppender. While this is a common solution to avoid blocking the current thread until the event is sent to Sentry, it is recommended to rely instead on the asynchronous connection provided by Raven.