Details
-
Improvement
-
Resolution: Unresolved
-
Major
-
None
-
None
-
None
Description
I'm using header and footer with my file appender and would like footers to be present in file when processes exit (JUnit tests mainly). I figured out a to achieve this by using status listeners and logger context (presented below) combined with shutdown hook. This is something that logback jar could probably in one form or another (spring framework for instance has similar feature for their context).
public class ShutdownHookStatusListener extends ContextAwareBase implements
StatusListener, LifeCycle {
private Thread shutdownHook;
@Override
public void addStatusEvent(Status status) {
}
@Override
public boolean isStarted()
@Override
public void start() {
if (!this.isStarted()) {
this.shutdownHook = new Thread() {
@Override
public void run()
};
Runtime runtime = Runtime.getRuntime();
runtime.addShutdownHook(this.shutdownHook);
}
}
@Override
public void stop() {
if (this.isStarted())
}
}