#StackBounty: #spring #spring-cloud #spring-logback #logstash-logback-encoder #spring-autoconfiguration Spring boot remove logback appe…

Bounty: 50

I’d like to have spring auto configuration which adds LogstashTcpSocketAppender.

What I have done:

  1. The LogstashTcpSocketAppender was added in to the LoggerContext from the LogstashAutoConfiguration.java
@ConditionalOnProperty(name = "logging.logstash.url")
public class LogstashAutoConfiguration {
    private String applicationName;
    private String logstashUrl;
    public LogstashTcpSocketAppender logstashAppender() {
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

        LogstashTcpSocketAppender logstashTcpSocketAppender = new LogstashTcpSocketAppender();

        LogstashEncoder encoder = new LogstashEncoder();
        encoder.setCustomFields(String.format("{"app_name":"%s"}", applicationName));



        return logstashTcpSocketAppender;

  1. After a while, the Spring Boot trigger a event will make the app reconfig. (for example I use Consul so I just change property in key/value storage, then spring refresh my context)
  2. It call the initializeWithConventions in the AbstractLoggingSystem.java
  3. then it will call the loadConfiguration in the LogbackLoggingSystem.java
  4. then it will stopAndReset(loggerContext). here it will stop all the appenders, and it will resetAllListeners();, which will clear the all logback listeners. (so I cannot use logback listeners for addition appenders again)

Are there correct way add Appender through spring auto configuration?
How can I prevent remove LogstashTcpSocketAppender from LoggerContext when spring makes the app reconfig?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.