Good day,

Intro
I have a web service (Spring + CXF) which has a 3-layer processing tier:

Dispatcher -> Service -> Processor

Chain of actions:
  • Request hits Dispatcher
  • Dispatcher validates, then gives request data to Service
  • Service writes data to DB, and chooses a Processor to process the data
  • Processor finishes, and returns a response to the Service
  • The Service writes the response to the DB
  • Service returns response to Dispatcher
  • Dispatcher returns response to client


Everything works fine and dandy and we're using this in production to distribute our payments amongst various payment providers.

Problem
The issue is that I have log statements scattered throughout the code. The problem with this is that the logs are "mixed" for every request.

Solution?
I'm looking for a solution to bundle the log messages together and write them out once.
One solution is to create a StringBuilder (one thread per request, thus safe) instance in the Dispatcher and carry this all the way throughout the execution stack, append log messages to the instance where-ever, then before the Dispatcher returns I write it out.

However, this is intrusive and I would need to change my API.

I was wondering if there's a way to do something similar to a method trace interceptor, but instead of doing one method, do an entire conversation. Does Spring provide such functionality?

All-in-all I want to replace all calls to:

Code:
log.info("blah");
with:

Code:
sb.append("blah\n");
then write it out once at the very end:

Code:
log.info(sb.toString);
On an aside, CXF has it's own SOAP logging (for which I submitted a patch here: https://issues.apache.org/jira/browse/CXF-2177 ) which I can hopefully ingrate into my "bundled log" solution.