tags:

views:

25

answers:

2

Hi all,

We have a testbed scenario we are developing for an integration test. The idea will be to run our code on two machines on an isolated network. We have various log messages set up within the code and this is working fine. However, we would like to log interactions from the two machines to a common log so that we can trace the interactions between them.

To this end we could like to identify the machine that raised the log message. My first thought was we may be able to do this with conversion patterns but can't see a pattern in the reference to achieve this.

I suppose my question is in two parts. First is this possible, and secondly if not, does the community have any ideas as to how we might achieve this.

Many Thanks.

Simon

+1  A: 

AFAIK it is not possible with an existing pattern. My first thought is to use Log4j's NDC or MDC. You will have to explicitly set the hostname in one of these contexts for each thread you start, so it is a bit of a hassle.

Kristoffer E
Thanks .. and yes I see what you mean regarding the hassle, but at this stage .. options are options .. so many thanks for the reply.
Simon Rigby
Thanks very much for your suggestion. The upshot is that we are now using the JDBC appender to log to a 'logging server' on our test network and using N/MDC to tag up log entries allowing us to trace flow backwards and forwards between the two machines.Thanks again.
Simon Rigby
I am glad I could help!
Kristoffer E
A: 

Consider using a Java property or environment variable setting for each deployed application and access it in your Log4J implementation.

johnnieb
My immediate thought is we would have to revisit every debug statement and inject this value .. unless I'm missing a detail in your suggestion. Thanks for the reply.
Simon Rigby