[I sent this message the other day to the dev mailing list and got no
response. I'm now sending this to the log4j user mailing list in case anyone
has any feedback for me. Thanks in advance.]

I'm migrating my application to use log4j and need to define a message
format that's compatable with an output format already in place from my
original logging code. There are two formats I can't currently seem to do:

1. I need to output the timestamp field as a two letter day of week string
-- Mo, Tu, We, etc.

2. I need to output the priority field as one character - D, I, W, E, F

It seems the formatting directives in PatternLayout don't allow for this.
They allow you to truncate fields to a max value, but they're truncated from
the front, such that the directive '%.1p will truncate INFO to 'O' and not
'I'

I looked through the latest log4j code, and found a way to patch this
functionality in by adding another formatting directive similar to the '.'
but using a '#' instead.

It will similarly define the max length for a field, BUT it will truncate
the trailing characters rather than the leading characters.

Examples:

        %d{E}   -> Tuesday
        %.2d{E} -> ay (original truncate directive)
        %#2d{E} -> Tu (new truncate directive)
        %p -> INFO
        %.1p -> O
        %#1p -> I

In order to do this, I needed to make minor patches to 3 files:

- org.apache.log4j.helpers.FormattingInfo.java
- org.apache.log4j.helpers.PatternConverter.java
- org.apache.log4j.helpers.PatternParser.java

I'd be happy to submit these patches in the hopes that this functionality
could be added to the code base.

I'm assuming all I need to do is send mail to dev mailing list with the
subject PATCH, or [PATCH], and then include in the message the three diff -c
outputs?

Is this kind of functionality useful to others?

Is this the approach I should be taking when proposing changes?

Thanks in advance.

Doug


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

Reply via email to