Something like this:
import org.apache.log4j.*;
public class MyClass extends org.apache.log4j.FileAppender
{
private static Priority minimumPriority = Priority.ERROR;
public void append(LoggingEvent event)
{
if (event.isGreaterOrEqual(minimumPriority))
{
super.append(event);
}
}
public static void setMinimumPriority(Priority p)
{
this.minimumPriority = p;
}
public static void enableInfo()
{
this.setMinimumPriority(Priority.INFO);
}
public static void enableDebug()
{
this.setMinimumPriority(Priority.DEBUG);
}
}
Make sure that in your log4j.properties, you include this appender just like a FileAppender. Set the default priority in log4j.property to INFO so that it receives all events and can filter them on its own.
Jon Emerson
http://www.jonemerson.net/