You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by CheapLisa <li...@purpleblade.net> on 2008/08/07 22:42:25 UTC

Distributed Logging Problem (log to remote database possible?)

We have six machines involved in a transaction (Identity Provisioning /
Identity Integration).  In this scenario ata is sent from a hub out to six
machines.

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?  I suppose the only thing really needed to do this
is the ability for Log4J to log a message to a remote database.  Each
machine would be logging messages with a message_id unique to that
transaction so I could write a query to show me all messages for that
transaction alone.

I need the ability to log to all of the following databases: Oracle,
PostgreSQL, Derby, MySQL


javatek
-- 
View this message in context: http://www.nabble.com/Distributed-Logging-Problem-%28log-to-remote-database-possible-%29-tp18879250p18879250.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

Re: Distributed Logging Problem (log to remote database possible?)

Posted by Jeff <jl...@gmail.com>.
On Thu, Aug 7, 2008 at 3:42 PM, CheapLisa <li...@purpleblade.net> wrote:
>
> We have six machines involved in a transaction (Identity Provisioning /
> Identity Integration).  In this scenario ata is sent from a hub out to six
> machines.
>
> 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?  I suppose the only thing really needed to do this
> is the ability for Log4J to log a message to a remote database.  Each
> machine would be logging messages with a message_id unique to that
> transaction so I could write a query to show me all messages for that
> transaction alone.
>
> I need the ability to log to all of the following databases: Oracle,
> PostgreSQL, Derby, MySQL
>

org.apache.log4j.jdbc.JDBCAppender seems to be the place to start.

Or SyslogAppender, with a centralized syslog server writing to a
database, but support for a good syslog/database bridge is somewhat
lacking. The specs for the relatively new rsyslog say it supports a
database backend, but some accounts I've read say that the rsyslog
system as a whole is still a bit raw. I have not used it myself. Not
log4j related, but I use syslog-ng with a mysql backend, but I have
not been pleased with the un-refined method used to get syslog records
into the database.

-- 
Jeff

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Distributed Logging Problem (log to remote database possible?)

Posted by Michael Erskine <mi...@ketech.com>.
CheapLisa [mailto:lisa@purpleblade.net] 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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org