| > I think this is an important requirement; for Category X I
| would like to log
| > java.lang.Integer as "Integer: " + Integer.toString( theInt ), and in
| > category Y I would like to log it as Integer.toString( theInt ).
| >
| > Is it possible?
|
| Nope. You can't do that. An ObjectRenderer renders the same for all
| categories.

Is this a design flaw?

| If you need per-category rendering yo may have to write a Layout which
| knows about the types of Object you log (Integers in your example), e.g.
| a subclass of PatternLayout which recognixes custom conversion
| characters related to your logged Objects.

Sounds like a good idea.

| Actually, in your example you can just use PatternLayout without any
| extension. Basically the %m ends up being populated by calling toString
| on your object (unless you explicitly register an ObjectRenderer for
| Integers), so you could have a pattern "Integer: %m%n" on Category X and
| "%m%n" on Category Y and the effect should be as you described.

This imposes a category per type(?), which is not what I want. I want each
category to have a particular formatting of an arbitrary number of types
irrespective of what toString() for the objects returns. E.g. for
java.net.InetAddress could possible strings be the hostname, the raw
IP-address, or both, preferrable formatted in a flexible way. In other
words, the stringification of an object passed to the category should be
formatted according to other method calls on the object than toString(). The
ObjectRenderer interface hides an implementation of how this is done for
each type, but as I found out (and you confirmed) log4j stores renderers
globally rather than on a per Category basis.

I probably miss a few things, but it seems like the LoggingEvent doesn't
contain the original Object (only the message i.e. the string version
(toString() of it) passed from the application. The LoggingEvent is passed
to each member of the list of PatternConverters from PatternLayout and ends
up being passed to the overrided convert(LoggingEvent) method. How do I get
hold of the original object from this point?

I certainly like the idea of having rules (patterns) for conversion of
different types, but I guess the PatternLayout class is no good for this(?)

Any suggestions for a flexible design and some hints how to implement it?

--

Thomas


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

Reply via email to