Im using Logback to log from an integration framework. All integration’s runs from within the same Java VM, and uses one logback.xml for configuration. They are all in separate packages, and I have set it up so they all log to their own file using a rolling file appender (just using a simple class=”x.y.z” etc). This is working fine.
However, all of the integration’s reference another jar file, which is a shared library. I can setup an appender for classes within this shared library, but having the logs go to yet another file makes tracing extremely difficult. For example the first log will appear in integration_one.txt, the next in shared_lib.txt, and the next back in integration_one.txt.
I need to configure logback so the shared library logs end up in the same file as the integration that called it.
The only way I can think of doing it would involve logging all logs from a thread that starts in package x to file y but I don’t know of a configuration that would accomplish this.
Does anybody have any ideas?
Unfortunately, Logback just doesn’t work that way.
The classes in the jar file undoubtably initialize their own appenders, and typically use their fully qualified class name to do so.
The part of the configuration that controls the file to which logs are appended uses that fully qualified class name to direct the log entries to the appropriate file.
In short, a class can have its logs directed to one or more appenders, but I’m not aware of any way, with third-party code, to have the same class log to different appenders depending on some external factor.
If you had written the classes in the jar file, then you could potentially pass them a logger to use based on the context, but I’m guessing that you don’t have the source code or don’t want to modify it.