Configuring Logback in SpringBoot using

I have a Java Spring Boot application that we are switching to use Sentry (from Errbit).

We are using the Logback appender, since that is what we were using for our previous solution.

We would like all of our configuration to be in a single file.

Right now, the only way we can figure out how to do that is:

public static void main(String [] args) {
    System.setProperty("", "");, args);

However, that requires us to use dsn = ..., environment = ..., etc. instead of sentry.dsn = ..., etc. That makes it difficult to ensure that the Sentry variables don’t conflict with other application-specific config that may already be there.

We tried several other options, including adding this:

private Environment env;

public void postConstruct() {
	String[] sentryProps = {
        // etc. ...

	for (String prop : sentryProps) {
		System.setProperty(prop, env.getProperty(prop));

The problem is that @PostConstruct runs too late in the startup process to catch things like database connection errors.

Also, this is a really bad hack.

Is there a better way to get the Sentry properties from the file?

You can create under src/main/resources and put all sentry configuration there.
Then simply init sentry before spring boot application startup.

public static void main(String [] args) {
    Sentry.init();, args);

It’ll lookup for senty properties under src/main/resources and your sentry connection will be initialized before application startup.
This is the way I’ve configured, not sure is it an ideal way to do so.

That still does not solve my issue, namely that I want to be able to use a single configuration file (that being my to have all configuration. I want this file to be able to be modified for each deployment, which your suggestion does not solve.

I ended up doing it like this (note that since this thread was started I have converted this application to Kotlin):

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
import org.springframework.boot.runApplication
import org.springframework.context.ApplicationListener
import io.sentry.Sentry

class Application

fun main(args: Array<String>) {
    runApplication<Application>(*args) {
		this.addListeners(ApplicationListener<ApplicationEnvironmentPreparedEvent> {
			val env = it.environment

			// Copy over all `sentry` properties into the system properties so Sentry can find them
			for (propName in arrayOf("dsn", "environment", "")) {
				System.setProperty("sentry.$propName", env.getProperty("sentry.$propName"))


It’s not the best or cleanest way, but it accomplishes my requirements.

Then maybe you can pass all sentry parameters like environment and in sentry.dsn which is initialized in

for eg. add this property in your


Then you’ll only need to call sentry.init() in main(). Using this you can skip setting up system properties.