LogMX and the Log4J SocketAppender

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

Moderator: admin

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

LogMX and the Log4J SocketAppender

Post by lost_traveller »

Does LogMX work with the org.apache.log4j.net.SocketAppender like chainsaw? and if so how do you configure it?
admin
Site Admin
Posts: 555
Joined: Sun Dec 17, 2006 10:30 pm

Post by admin »

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

Post by lost_traveller »

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

Post by lost_traveller »

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: 555
Joined: Sun Dec 17, 2006 10:30 pm

Post by admin »

Thank you for this code. Indeed, it seems to match SocketAppender specifications (http://logging.apache.org/log4j/1.2/api ... ender.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.
Post Reply