Very simple -

Just extend PatternLayout (thats what your example looks like), or any other
layout and over-ride the getHeader() and/or getFooter() methods. Then just
name your class as the layout in the config file.



scott


-------------- ex -------------------
public class MyPatternLayout
    extends PatternLayout
{
    public 
    MyPatternLayout()
    {
        super();
    }

    public String 
    getHeader()
    {
        Date now = new Date();
        SimpleDateFormat sdf = 
            new SimpleDateFormat( "yyyy.MM.dd 'at' HH:mm:ss.SSS z" );
            
        StringBuffer buf = new StringBuffer();
        buf.append( "=== My Log File ===\r\n" );
        buf.append( "Log started: " );
        buf.append( sdf.format( now ) );
        buf.append( "\r\n" );
        buf.append( ReleaseVersion.getVersionString() );
        buf.append( "\r\n\r\n" );

        String superHeader = super.getHeader();
        if ( superHeader != null ) {
            buf.append( superHeader );
        }
        
        return new String(buf);
    }
}

-----Original Message-----
From: McKinnon, Cory [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 30, 2002 6:32 AM
To: '[EMAIL PROTECTED]'
Subject: Help with Log4j automatic header generataion


Hi,

I am simply prototyping a very small Log4j application, however, one of the 
requirements we must prove to the client is for an automatic header
generation 
for the log messages.  Example:


DATE                            FUNC    CLASS / LINE NUMBER            LVL
MESSAGE
2002-07-29 15:26:08,086 [main] (log4jexample.TestLogging : 16) DEBUG -
message1
2002-07-29 15:26:08,101 [main] (log4jexample.TestLogging : 17) INFO  -
message
2002-07-29 15:26:08,101 [main] (log4jexample.TestLogging : 18) WARN  -
message3
2002-07-29 15:26:08,101 [main] (log4jexample.TestLogging : 19) ERROR -
message4
2002-07-29 15:26:08,164 [main] (log4jexample.TestLogging : 20) FATAL -
message5

Any help is much appreciated.

Cheers,

Cory


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to