CheapLisa [mailto:[EMAIL PROTECTED] wrote:
> I want to log information on the hub and the six machines in one place (a
> database residing on yet another machine).
>
> Is this possible to do?

Sure, this is a rather common requirement. You can detach the database logging 
entirely by configuring a org.apache.log4j.net.SocketHubAppender on each of 
your six machines then creating a simple socket client that connects to each 
machine and receives all the LoggingEvent objects which it can write to any 
database at its leisure (preferably asynchronously in a background thread with 
a BlockingQueue or somesuch).

Just for a starter hint the very simplest client to connect to a single remote 
SocketHubAppender and log the messages locally would look like this...

---------------------- >8 --- CUT HERE --- >8 --------------------

public class RemoteLoggingClient {
        static Logger log = Logger.getLogger(RemoteLoggingClient.class);
        /**
         * @param args
         */
        public static void main(String[] args) {
                BasicConfigurator.configure();
                // connect to remote server that is logging with log4j
                try {
                        Socket s = new Socket("whateverserver", 9009);
                        ObjectInputStream ois = new 
ObjectInputStream(s.getInputStream());
                        while (true) {
                                LoggingEvent event = (LoggingEvent) 
ois.readObject();
                                log.debug("remote event:'" + event.getMessage() 
+ "'");
                        }
                } catch (UnknownHostException e1) {
                        log.fatal("problem:", e1);
                } catch (IOException e1) {
                        log.fatal("problem:", e1);
                } catch (ClassNotFoundException e) {
                        log.fatal("problem:", e);
                }
        }
}
---------------------- >8 --- CUT HERE --- >8 --------------------

You can scale such a thing up to connect to many servers, keep the connections 
up, render the logged events, queue them for writing to the databases, write to 
the databases asynchronously with DB connection pooling and recovery, etc., 
etc. Lots of scope for fun here!

Regards,
Michael Erskine.



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

Reply via email to