logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Wagner <Claus.Wag...@ascom.ch>
Subject Re: Escape sequences
Date Wed, 12 Sep 2001 08:14:34 GMT
"Klovance, Joe" wrote:
> I need to modify log4j to so that I can use a delimiter between the fields
> and be able to replace any occurance of the delimeter in any of the paterns
> with an escape sequence. Where in the code would I do that?
> Joe Klovance

If you would only have the first demand, namely putting a delimiter
between the fields, you would just use a new pattern, e.g.,
"%-4r|%t|%a|%h|%-5p|%c%m%n" if you want a "|" as delimiter. The easiest
way is to choose a delimiter which is garuanteed not to be in any

If you really need to parse the message string, a (good?) place for
doing this is in the forcedLog(...) methods of class Category. But then
you have to subclass from Category and overwrite the forcedLog method

  void forcedLog(String fqcn, Priority priority, Object message,
Throwable t) {

    // apply your patches here: change for separators, escape them, etc
    patchMessage( message ); // <--- new

    callAppenders(new LoggingEvent(fqcn, this, priority, message, t));

But then you must tell CategoryFactory to produce instances of your new
category class. Regarding extending log4j in this way you should have a
look at

Have a closer look at the last sentence in this document: 

"There is one a word of caution concerning the use of configurators that
may create Category instances (such as PropertyConfigurator and
DOMConfigurator). Since these configurators do not know about our
extensions, any Category instances they create will not be
AppServerCategory instances. To prevent this problem, any
AppServerCategory that one might want to be configured through a
should be instantiated before the configure method is invoked. In this
way, the configurator will configure the AppServerCategory that already
rather than creating an instance of its super class. "

Baybe it's not enough just to subclass from Category?

Claus Wagner

To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org

View raw message