tags:

views:

106

answers:

1

I have an application in which we have already a logger file. But i need to implement that logging into one of the process flow. Where I need to write the code for logging for this process flow?

A: 

To answer this properly, we need:

  1. the logging mechanism you're using (e.g. log4j)
  2. what delineates or determines the concept of a flow within your process. e.g. is each flow contained within a thread ? Is a flow related to a data item ? (e.g. a trade id / stock entry id or similar)

One approach is to pass a contextual object around through your system which contains the information surrounding that flow (e.g. the id of a particular entry related to that flow), and then log via that object, and the object would append the contextual info or similar. This can be a little heavyweight if not done with care, since you could end up affect a lot of interfaces of objects within that flow (ignore aspect-related solutions)

If your flow is delineated by threads (i.e. a flow occurs within a thread - in a servlet container or similar), you can make use of ThreadLocal variables to hold this info. If you're using Log4j then you should take a look at mapped diagnostic contexts

Brian Agnew