Novell is now a part of Micro Focus

Appender for Log4j

Novell Cool Solutions: Tip
By Alfredo Luiz Santos

Digg This - Slashdot This

Posted: 15 Feb 2006

This article shows you how to develop a new appender to log4j. This is useful in development using Novell APIs.


1) Import required classes:

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

2) Declare your class:

public class MyAppender extends AppenderSkeleton{

3) If you need extra parameters, declare them:

    private String Text3;
    private int Value1;
    private int Value2;

4) Declare methods to manage your parameters:

    public void setText3(String text3) {
        Text3 = text3;

    public String getText3() {
        return Text3;

    public void setValue1(int value1) {
        Value1 = value1;

    public int getValue1() {
        return Value1;

5) You must declare this method:

    public boolean requiresLayout() {
        return false;

    public void close() {
6) And the main method of your implementation:

    protected void append(LoggingEvent event) {
        String level=event.getLevel().toString();
        String event.getMessage().toString();

The main method enables you to get the log (event.getMessage().toString()) and other data. With this data you can send the log to another application.

7) To use the log in your application, you can use this sample:


log4j.rootCategory=info, mylog

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates