Custom Log4J Appender I have written a Custom Log4J Appender which is responsible for sending the log message to a third party service asynchronously. It is expected to be called every millisecond.

I ran FindBugs on this code, it didn't report anything unusual. But before releasing this code to production, how can I know if this code has any issues with it?

package com;

import java.util.ArrayList;
import java.util.Iterator;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;

public class MyAppender extends AppenderSkeleton {

    public MyAppender() {

    }

    public void append(LoggingEvent event) {
        ArrayList&lt;LoggingEvent&gt; buffer = new ArrayList&lt;LoggingEvent&gt;();
        buffer.add(event);
        flushBuffer(buffer);
    }

    public void flushBuffer(ArrayList&lt;LoggingEvent&gt; buffer) {
        for (Iterator&lt;LoggingEvent&gt; i = buffer.iterator(); i.hasNext();) {
            try {
                LoggingEvent logEvent = (LoggingEvent) i.next();
                String messageRecievied = (String) logEvent.getMessage();
                //System.out.println(messageRecievied);

            } catch (Exception e) {

            }

        }

    }

    @Override
    public void close() {

    }

    @Override
    public boolean requiresLayout() {

        return false;
    }

}
First, I don't think the close() method is following the contract, from the javadoc: 


  It is a programming error to append to a closed appender.


Therefore, your close() method should be implemented like this:

@Override
public void close() {
    this.closed = true;
}


Note that closed is a protected field in AppenderSkeleton. 

Then, change append to something like (add the @Override as well):

@Override
public void append(LoggingEvent event) {
    if (!this.closed) {
        ArrayList&lt;LoggingEvent&gt; buffer = new ArrayList&lt;LoggingEvent&gt;();
        buffer.add(event);
        flushBuffer(buffer);
    } else {
        // It is a programming error to append to a closed appender.
        throw new RuntimeException("Attempting to append to a closed Appender.");
    }
}


Next, does flushBuffer need to be public? It should probably be private.

Finally&mdash;and this is more of a nitpick&mdash;you don't need to declare the default constructor since it's empty and the compiler will create one for you. It'll make your code a little cleaner as well.