I'm using logback's DBAppender to log the http request/response into the DataBase (logging_event) table in my Springboot app.
Below given is the Java configuration class for DbAppender.
@Configuration
public class LogbackConfiguration {
@Bean
public DBAppender dbAppender(DataSource ds){
DBAppender dbAppender = new DBAppender();
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); Logger logger = loggerContext.getLogger("org.zalando.logbook"); loggerContext.start();
DataSourceConnectionSource connectionSource = new DataSourceConnectionSource(); connectionSource.setDataSource(ds );
connectionSource.setContext(loggerContext);
connectionSource.start();
dbAppender.setConnectionSource(connectionSource);
dbAppender.start();
logger.addAppender(dbAppender);
return dbAppender;
}}
I have another configuration class that has configuration properties and the values of those properties can be changed dynamically. I'm using the @RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope) annotation to get the new values of the config properties on the fly.
The DBAppender works fine, except when I make any changes to any of the configuration properties externally (changing the value of an existing property or adding a new config property in Consul) while the app is running.
After I make any changes to any config property externally, the DbAppender stops logging into the DB table. Console logger continues to work fine. No error/exception message. I will have to restart the app everytime after I change a config value to get the DbAppender working.