1

I have a Java API library. The library intended to test functionalities of a device. Later these libraries are exposed as webservices so that non-java programs can also access it. I have a single EAR which contains the beans and dependent libraries and this EAR is deployed in to a weblogic server.

Simultaneously we are testing these webservices for multiple devices from multiple agent machines and all the logs from the library and captured in the weblogic console log file. I've configured log4j in the weblogic server. Now the issue I am facing is that, I am unable distinguish from which devices/ip these logs are from.

What is the better way to identify the logs based on device MAC/IP ? I googled and got inputs like log4j MDC can be used for this application. Since I don't have any servlet written by me, I am not sure whether I can proceed with MDC.

Please guide me to choose the best way to configure logs per MAC/IP.

Eyal
  • 3,412
  • 1
  • 44
  • 60
appu
  • 538
  • 10
  • 24
  • [This excellent answer explains how to add usernames using MDC](http://stackoverflow.com/a/6116385/150992) - it's more detailed than @MaDa's answer below, and will probably be useful. – Eyal Apr 14 '13 at 12:37

1 Answers1

0

MDC/NDC is not dependent on servlets; the fact that they're mentioned in the javadoc is only to show an example. You can use it in any Java application.

MAC/IP is not visible to a web service, so you have to send it explicitly as a part of a web service message. Once you do, in the handler method, call

NDC.push("127.0.0.1"); // example IP obtained from the web service
MDC.put("IP", "127.0.0.1");

and use %x or %X{IP} in the respective PatternLayout.

MaDa
  • 10,511
  • 9
  • 46
  • 84