Configuring the logback appender

Adding the logback appender will allow you to send reports to BugSnag using your existing log statements.

Basic configuration

Add the following to your logback.xml:

...
<appender name="BUGSNAG" class="com.bugsnag.BugsnagAppender">
    <apiKey>your-api-key-here</apiKey>
</appender>

<root level="INFO">
    <appender-ref ref="BUGSNAG"/>
</root>
...

If you wish to access the Bugsnag client created by BugsnagAppender, you can access it via Logger.getAppender().

Logger rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
BugsnagAppender appender = (BugsnagAppender)rootLogger.getAppender("BUGSNAG");
Bugsnag client = appender.getClient();

Using the logback appender

Setting the severity

The severity of an error in BugSnag is determined by the logger method used to send the message (error/warn/info):

logger.error("Something went wrong here", new RuntimeException("Non-fatal"));
logger.warn("Something went wrong here", new RuntimeException("Non-fatal"));
logger.info("Something went wrong here", new RuntimeException("Non-fatal"));

Severity is displayed in the dashboard and can be used to filter the error list.

Setting metadata

You can add additional metadata to an error report by using the BugsnagMarker class to add a callback:

logger.warn(new BugsnagMarker(new Callback() {
    @Override
    public void beforeNotify(Report report) {
        report.addToTab("message", "id", "12345");
    }
}), "Something went wrong here", exception);

Metadata can also be added globally by adding the following to your logback.xml file:

<appender name="BUGSNAG" class="com.bugsnag.BugsnagAppender">
    ...
    <metaData>
        <tab>
            <name>system resources</name>
            <key>
                <name>memory</name>
                <value>10MB</value>
            </key>
        </tab>
    </metaData>
</appender>

Further configuration

If you are using the logback appender then other configuration should go in the logback.xml file, check out the configuration options reference.

To capture unhandled exceptions you will also need to configure the bugsnag client in your code (see basic configuration).