logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tmu...@moneynet.com
Subject Idea on how to make Log4J more expandable during runtime.
Date Mon, 06 Aug 2001 17:44:52 GMT
Hello,

     I was thinking, I think I've found a way that we can make Log4J
expandable at runtime in terms of adding attributes to the Category/Event
instead of extending classes.
What if the category class provided an optional method like this:
"debug(Object message, Map extra)" that took a map of the fields you want
associated with the Category/Event class.
Then we'd need a new Layout class that worked just like the PatternLayout
class but instead of "chars" it used word replacement. There could still be
"default" fields like date/time, thread, etc. but also allow for new ones.
The fields the PatternLayout uses to find the values would be the same
names as the ones in the Map passed to it.
The category class would then build a generic LogEvent message and hold
onto the new values and pass them around to the appenders/layouts as
normal, as long as the new Layouts know how to deal with the new patterns

Here's an example of what I'm thinking..

// Create the category instance
Category cat = Category.getInstance("TimsCat");

// Create the new fields we want to log
Map extraFields = new HashMap();

extraFields.put("UserName", "Joe");
extraFields.put("PassWord", "password");

// Log the message
cat.debug("Logging user info..", extra);


Then on the PatternLayout would be something like..

// Set up the pattern to print the new fields and some of the default
fields
// This would print something like:  "11:00:00 - Thread 0 [DEBUG] - Logging
user info..., UserName=Joe Password=password"
String pattern = "{$date}{HH:mm:ss} - {$thread} [{$priority}] - {$message},
UserName={$UserName} Password={$PassWord}";


This way we no longer need to extend any classes to add new fields to the
category/event, at least that is what I'm hoping for


What do you think? Does this sound like a good idea? Is there anything that
prevents this that I've missed?

Thanks,
  - Tim
____________________________________________________
Timothy G. Mullé
Senior Software Architect
Reuters Valley Forge Solutions Center
1000 Madison Avenue
Norristown, PA 19403-2432

Phone: (610) 650-8600 x8340
Fax:      (610) 650-8170


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


Mime
View raw message