I'm running Spring Boot and I want to add logging to my application. All examples have the following for the main Application entrypoint:
private static final Logger log = LoggerFactory.getLogger(Application.class);
However, I want the same log variable visible (as Singleton) across all my application components (services, controllers, etc.). How would I do that? Thanks!
You can use springs IoC container to achieve this.
just configure a bean like this in a @Configuration cass
@Bean
public Logger log() {
return LoggerFactory.getLogger(AnyClassYouWant.class);
}
and inject it with @Autowired in your class
class WhatEver {
@Autowired
Logger log;
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With