When writing our library we sometimes have to adapt our code depending on the version of Logback on the class path. Until now the only option is to use java reflection and check for the presence of some methods introduced in specific versions. For instance, we know we have at least version 1.3.0 if ILoggingEvent#getInstant() is found... Although this approach works for most of our case it is clear that a more reliable option would be great. Possible options that come to my mind are:
- provide a static method/field with the version in an utility class like LogbackVersion. This field would be set at build time.
- add the version in the MANIFEST and rely on Package.getImplementationVersion() to retrieve it at runtime
Regarding the last option, the MANIFEST already contains a Bundle-Version entry - however there is no easy way to access it (compared to the Package.getImplementationVersion()). |