Logback programmatic configuration + DI


I am developing extension (JsonEncoder) for the Logback, and it requires
some application services injected.

How can I bootstrap the Logback at application startup to register JsonEncoder
instance with resolved dependencies by DI?
As a result, I want to have programmatically configured logger, and have extension
with references to application services injected.

Is this possible? If yes - how to achieve?

Thank you in advance!

Hi @hexwit,

You can have a custom logger configurator, but it usually instantiate everything manually to setup Logback or any other logging framework. The logging configuration happens before the dependency injection framework kicks in, and it is that way to log all the instantiations and injections.

I would say that if you push too hard you will find a way to do that, but it does not mean it is recommended. What exactly are you trying to inject?


​​I’d like to print server version from the configuration to the logs.

And another reason why I though to use programmatic configuration: when use in logback.xml - class cannot be found.

Tried different ways, with no luck.