We've added this capability to a number of appenders (including SocketAppender), available from the log4j CVS repository. See http://cvs.apache.org/viewcvs.cgi/jakarta-log4j/src/java/org/apache/log4j/net/SocketAppender.java?rev=1.20&view=auto
There are two parameters that can be set in the appender configuration: application and hostname. If you set them, they'll each be added as a 'property' of the event. By the way, Chainsaw V2 was designed to specifically support routing of events to individual tabs in the UI based on these properties. If you have further questions, let us know. Scott -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tue 12/23/2003 9:34 AM To: [EMAIL PROTECTED] Cc: Subject: centralized logging with application ids I'm working on a distributed system consisting of multiple processes per machine and multiple machines. We're currently using the SocketAppender and SimpleSocketServer to implement centralized logging. But I'd like for every log-server client to "automatically" put an application ID to every log message to identify the host/processid/servername from which each log message is coming. What is the best way to do this? The most obvious way to me was to add this information to the MDC at the very beginning of each main program. This works fine for programs in which we get to write the main program. But this doesn't work so well for programs in which we don't write the main program. We can create a "wrapper" main that sets the MDC and then calls the third-party main method. But it's still easy to mess up thread inheritance. Here's a simple example: class ITL { static InheritableThreadLocal itl = new InheritableThreadLocal(); public static void main(String[] args) throws Exception { itl.set("inherited from main"); new Bar(); System.gc(); System.runFinalization(); } static // oops! static initializer runs before ITL was initialized { System.out.println("Foo thread local value = " + Foo.fooITLV); } } class Foo { static Object fooITLV = ITL.itl.get(); } class Bar { public void finalize() { // oops! finalizer thread doesn't inherit from main thread System.out.println("Bar thread local value = " + ITL.itl.get()); } } In addition to this simple example, threads attached via JNI and windows signal handler threads won't inherit thread locals from the main thread. And if I can think of all these problems so quickly, I'm sure there are other problems lurking out there. So given these (admittedly somewhat obscure) problems, I thought of another solution -- create an Appender that forces the MDC to contain the host/processid/servername info, and make that Appender the first one to get run in my log4j client-side config files. But that just feels hackish, since it presumes that the LoggingEvent hasn't had its getMDCCopy() method called, and it forces me to make sure my log-server clients' log4j config files always list this specialized Appender before their SocketAppender. This solution works better than the first solution -- it catches the obscure cases. But I personally I don't like it. It totally breaks abstraction -- relying on knowledge of log4j internal MDC caching behavior on one hand and on the other hand forcing the log-server client to hack their log4j config file. Do you have any suggestions? Thanks, --Ian --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
