Object started = invocation.getMetaData(ThreadLocalAppender.LOG, ThreadLocalAppender.LOG);
ArrayList log = null;
if (started != null)
{
// Some earlier invocation started the logging
if (ThreadLocalAppender.getList() != null)
started = null;
else
{
// We are the first, start the logging
log = new ArrayList();
ThreadLocalAppender.setList(log);
}
}
try
{
// Perform the invocation and attach the log when we started it
Object response = invocation.invokeNext();
if (started != null)
invocation.addResponseAttachment(ThreadLocalAppender.LOG, log);
return response;
}
finally
{
// If we started the logging, stop it
if (started != null)
ThreadLocalAppender.setList(null);
}