logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Britton <...@hp.com>
Subject New Appender: PatternFileAppender
Date Tue, 02 Sep 2008 20:38:26 GMT
Hello --

I'm not sure if this is the correct way to do this, but my colleague and
I have developed a new appender called a PatternFileAppender.  I did not
see anything else like this in the log4j distribution, but it helped us
solve our particular problem, and I think it's a good general purpose
appender.  If someone knows of another appender like this, I would love
to hear about it.

I went to make an official patch for log4j 1.2, but I found that the
code needed to be compatible with 1.2 source compatibility level.  Since
the code uses generics in it's use of the LinkedHashMap data structure,
it needs 1.5 or later to compile correctly.

Anyway, I've attached the file, if there is an "official" way to do
this, please point me in the right direction.

Here is the high-level details of the appender:

* Can process a filename as a pattern, with all substitutions available.
  (e.g., MDC, date, variable, level, class, ...)

* Interesting use cases we are using it for:
    - Separate log file per "thread" using MDC (note that "thread" could
      be any separation desired, log level, date, time, etc).

* Keeps a cache of the latest 20 open file streams, so as not to
  overload the OS/filesytem/etc

* Adds performance penalty in that each log message will generate an
  extra pattern lookup.  Note that this already happens for the message
  itself, so this does not seem like a huge impact.

Let me know any feedback...  Thanks!

David Britton <dpb@hp.com>

View raw message