package eu.hinsch.spring.boot.logging;

import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.logging.LoggingApplicationListener;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.Map;

/**
 * Created by lh on 06/04/15.
 */
public class ExtendedLoggingPropertiesListener extends LoggingApplicationListener {

    private static final String KEY_PREFIX = "logging.properties.";

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ApplicationEnvironmentPreparedEvent) {
            addLoggingProperties((ApplicationEnvironmentPreparedEvent) event);
        }
        super.onApplicationEvent(event);
    }

    public void addLoggingProperties(ApplicationEnvironmentPreparedEvent event) {
        ConfigurableEnvironment environment = event.getEnvironment();

        new RelaxedPropertyResolver(environment)
                .getSubProperties(KEY_PREFIX)
                .entrySet()
                .stream()
                .forEach(entry -> System.setProperty(entry.getKey(), entry.getValue().toString()));
    }

    /**
      * ideally this would be run before org.springframework.boot.logging.LoggingApplicationListener (+11)
      * but after org.springframework.boot.context.config.ConfigFileApplicationListener (+10)
      * so we could simply insert the properties in between those steps, but unfortunately there is
      * no guaranteed way to do that, so we run afterwards and re-initialize the entire thing via super class.
      */
    @Override
    public int getOrder() {
        return Ordered.HIGHEST_PRECEDENCE + 12;
    }
}

@@ -436,34 +436,685 @@
 %0A * 
-Created by lh on 06/04/15.
+Listener to make properties from spring environment available in logging configuration.%0A * %3Cp%3E%0A * It re-uses the concept from spring boot of setting (system) properties and then reloading%0A * the logging configuration. As there is no stable way to hook into the existing reload by boot%0A * the same behavior is triggered once again reloading and initializing the logging framework twice%0A * (which would not be necessary if code like this would be integrated into LoggingApplicationListener).%0A * %3Cp%3E%0A * %3Cb%3EHowto use%3C/b%3E%3Cp%3E%0A * In application.properties:%3Cp%3E%0A * %7B@code logging.properties.some.key=Some Value%7D%3Cp%3E%0A * In logback.xml:%3Cp%3E%0A * %7B@code $%7Bsome.key%7D%7D%0A *%0A * @author Lukas Hinsch
 %0A */
@@ -1549,29 +1549,30 @@
     %7D%0A%0A    p
-ublic
+rivate
  void addLog

Update javadoc