You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Mark R Durman/CA/US/MQSolutions <md...@mqsolutions.com> on 2004/01/06 02:09:12 UTC
Optional Appender Layouts
I have an Appender that can produce serialized logging events or formatted
logging events. I wanted to support an optional Layout to determine which
output to produce. If a Layout was supplied it would be called to format
the event, otherwise the log event would be serialized.
However, support for optional layouts seems rather counter intuitive. That
is, if an Appender returns false to requiresLayout() a Layout is never
passed to the Appender even if one if supplied. On the other hand, if I
return true from requiresLayout and the user omits the layout, log4j spits
out an error. That's confusing for end users and requires documentation to
cover the behaviour.
Returning false from requiresLayout() implies that the Appender does not
require a layout, not that it doesn't ever use one. I believe it would be
more logical for log4j configuration to set an Appender's layout if one is
specified, regardless of the response from requiresLayout(). That way, an
Appender that doesn't use a Layout won't call it, an Appender that uses an
optional Layout can test for it's existence, and an Appender that requires
a Layout will continue to function as before.
This kind of operation would also apply to other Appenders (like the
JMSAppender). That has the capability of handling serialized log events
and formatted textual events (in XML, for example).
Regards
Mark Durman
MQ Solutions LLC