posted 6 years ago
It's not only done all the time, it's done in systems where the different JAR authors have different preferences in logging systems.
The logger is obtained via a static method. For example:
Static methods and pbjects are global to the classpath, so it doesn't matter whether this code is in the main WAR code or in an included JAR in WEB-INF/lib. All that's required is for you to code logging statements using that logger (or whatever logger applies) and to define one or more log appenders to output those log messages.
What's trickier is when your code uses log4j, but you want to also output log messages from third-party JARs that logged using apache commons logging or java.util.logging (JULI). In cases like that, you would have to include a log aggregator façade such as slf4j that acts as a common backend for all the other loggers and routes everything to your logger of choice.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.