LogMX and the Log4J SocketAppender

Here developers can talk about how to write a Manager for LogMX

Moderator: admin

lost_traveller
Posts: 6
Joined: Mon Mar 31, 2008 12:41 pm

LogMX and the Log4J SocketAppender

Postby lost_traveller » Thu Apr 03, 2008 8:36 am

Does LogMX work with the org.apache.log4j.net.SocketAppender like chainsaw? and if so how do you configure it?

admin
Site Admin
Posts: 418
Joined: Sun Dec 17, 2006 10:30 pm

Postby admin » Thu Apr 03, 2008 9:18 pm

Hello,

At the moment, LogMX doesn't handle Log4j SocketAppender, but you can write your own Log Manager that handles it. But since it's a common way to monitor remote logs, LogMX will surely be delivered with such a Manager in a next release.
To get more information on LogMX Managers, please see http://www.logmx.com/p_manager_dev.php

Please note that user-defined Managers can only be used with the Professional version.

lost_traveller
Posts: 6
Joined: Mon Mar 31, 2008 12:41 pm

Postby lost_traveller » Fri Apr 04, 2008 5:42 pm

ok thanks! we are currently evaluating logmx as a replacement for chainsaw, clearly we would require the socket reciever to completely remove any need for chainsaw; if I'm able to get write a socket reciever and get it working, and logmx meets all of our other requirements; then yes, we would be looking at purchasing a number of professional licences.

lost_traveller
Posts: 6
Joined: Mon Mar 31, 2008 12:41 pm

Postby lost_traveller » Fri Apr 11, 2008 1:39 pm

I have created a test calss for a user-defined log4j socket manager which works ok:

Code: Select all

   public static void main(String args[])
   {
      try
      {
         ServerSocket serskt = new ServerSocket(4560);
         Socket skt = serskt.accept();
         
         ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(skt.getInputStream()));
         // takes a few seconds...
         System.out.println("connected");

         org.apache.log4j.spi.LoggingEvent event = (org.apache.log4j.spi.LoggingEvent)ois.readObject();

         System.out.print(event.getLoggerName());
         System.out.print(event.getRenderedMessage());
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }


Would you be able to integrate this into a manager an put it in the next release?

admin
Site Admin
Posts: 418
Joined: Sun Dec 17, 2006 10:30 pm

Postby admin » Sun Apr 13, 2008 9:53 pm

Thank you for this code. Indeed, it seems to match SocketAppender specifications (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/net/SocketAppender.html).
But as you may have seen (link on previous message), LogMX Managers and "Auto Refresh" feature work this way:
- Periodically, the LogMX core asks the Manager the current size and timestamp for the input resource.
- If one of these values have changed since last time, LogMX core asks the Manager to read all bytes, starting from the last read byte
- LogMX makes the Parser process these new bytes (characters)

To use this SocketAppender code, the new LogMX Manager must support 'AutoRefresh' this way:
- put the bytes read from the socket in a local buffer, and wait for LogMX core to ask the current timestamp/size (this Manager may update these 2 values when new bytes are read from the Socket)
- send characters to LogMX and not instances of LoggingEvent (raw bytes read from socket can be sent to a new Log4JSocketAppenderParser, or this LoggingEvent object can be re-serialized in a more common file format)

LogMX v1.2.2 free version comes with an example of user-defined Manager: see "managers/" LogMX directory.
This directory also contains an Eclipse project and a Ant file so that you can compile this Manager.
To help you in writing this class, you can use the LogMX API Javadoc in LogMX "help/api/" directory.


Return to “Writing a Manager”

Who is online

Users browsing this forum: No registered users and 1 guest