LoggerContext changes when using Spring Cloud
See original GitHub issueHi,
I am using the Spring Boot 1.5 micrometer code and have found that the LoggerContext changes shortly after application startup (which I believe is related to our use of Spring Cloud). When the application starts io.micrometer.core.instrument.binder.logging.LogbackMetrics registers io.micrometer.core.instrument.binder.logging.MetricsTurboFilter, but when the application context is reloaded, LogbackMetrics is now pointing to the old LoggerContext. To get round this I created the following class:
@Component
public class FlexLogbackMetricsListener implements ApplicationListener<ContextRefreshedEvent> {
private final LogbackMetrics logbackMetrics;
private final MeterRegistry meterRegistry;
public FlexLogbackMetricsListener(final LogbackMetrics logbackMetrics, final MeterRegistry meterRegistry) {
this.logbackMetrics = logbackMetrics;
this.meterRegistry = meterRegistry;
}
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
logbackMetrics.bindTo(meterRegistry);
}
}
Is there a better way to do this? It works a treat, but does seem a little hacky.
Thanks
Nick
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:12 (6 by maintainers)
Top Results From Across the Web
How to change logback log level dynamically in spring boot ...
With slf4j you can get the LoggerContext and change the level. LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); context.getLogger( ...
Read more >Dynamically modifying Logger log levels in Spring Boot ...
Spring Boot uses logback as the logging framework by default. logback provides an interface to get logger and modify logger logging levels.
Read more >5 Ways to Change Log Levels at Runtime - DZone DevOps
The user will use the spring boot admin UI to change the log levels. Merely select the logger and change the log level...
Read more >Using Log4J 2 with Spring Boot - Spring Framework Guru
In this post, I will explain how to configure Spring Boot to use Log4J 2 over ... through application.properties, the bug changes the...
Read more >How to allow user to make permanent changes to log levels?
You could create a new config file (outside the container) and use it to ... File file = new File("/config/new/log4j2.xml"); final LoggerContext ctx ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In the end this is what I managed to get working:
You are completely right. I will head over to the spring-cloud-commons project and refer to this bug. Maybe they can help out some more. Thanks for the quick reply!