[logback-user] Logback DbAppender stops working when @RefreshScope annotation is used for config changes
Moser Baer
moserbaer135 at gmail.com
Wed Aug 18 00:44:30 CEST 2021
Hi,
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.
Could you please guide me on this issue?
Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20210817/8059c697/attachment.html>
More information about the logback-user
mailing list