[EMAIL PROTECTED] wrote: -
> There are a number of independent systems all logging using log4j to their
> own respective log files.  The intended use for this system is to keep
> track
> of daily, weekly, monthly..etc stats for a particular system (assumed in
> this case to be a single log).
>
> I'm trying to use the log4j Receivers to bring the logging events that
> post
> to those files (or any type of receiver (appender?, let me know if I'm
> getting the terminology wrong)) back into my system to handle them.  I
> need
> to grab the events as the Receiver gets them so I can convert them into my
> domain objects and do what I need with them.  It would be helpful if there
> were some event hooks that I could use for when a log message is received,
> but I haven't been able to find anything yet.

When I do this sort of thing I typically configure log4j on my remote apps to 
log to a SocketHubAppender - no changes to code required, I just add an 
appender to the log4j config, e.g.:-

# Socket hub appender that passes logs to anyone who connects on port 9009
log4j.appender.Socket=org.apache.log4j.net.SocketHubAppender
log4j.appender.Socket.Port=9009

Then in my remote "receiver" app I spawn simple threads to connect to each 
host's SocketHubAppender and grab all logging events with something like...

Socket s = new Socket("whateverhost", 9009);
ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
while (true) {
        LoggingEvent event = (LoggingEvent) ois.readObject();
        log.debug("remote event:'" + event.getMessage() + "'");
}

You can get fancy with it and have the "receiver" app do whatever you like with 
the messages: I tend to write them to a database (with a nice robust JDBC async 
appender I wrote :) ).

Hope that helps,
Michael Erskine.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to