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 Paul Glezen <pg...@us.ibm.com> on 2001/07/29 21:03:40 UTC

Configuring message bundles with Categories

A while back some people expressed a need for configuring message bundles
with categories via property files or XML files (I can't remember which).
It would be easy to provide this ability for XML configuration now that we
use the Java Bean convention of configuration.

For property files, because of the unique structure of the category line,
this may not be possible the way things are now.  However, the next best
thing would be to follow the manner in the appserver package whereby the
message bundle is configured on the category factory instead of a
particular category.  One misses the flexability of configuring a separate
message bundle for each category, but for cases where a single message
bundle suffices, it will do the job.

This would require modification of DefaultCategoryFactory to accept a
message bundle in its configuration - easy enough.  The sensitive part is
how to associate the DefaultCategoryFactory to the Hierarchy.  There is a
setCategoryFactory method on the Hierarchy class that I think is left over
from when I was wanting to set custome category factories on the Hierarchy.
Ceki was opposed to the idea of encouraging this kind of access to the the
hierarchy at the time; so I did something different for the customized
category case.

I would like to propose modifying
PropertyConfigurator.configureCategoryFactory(Properties) to set the
Hierachy's default category factory whenever the factory is an instance of
DefaultCategoryFactory.  This would allow DefaultCategoryFactory to be
configured with a message bundle and associated with the Hierarchy.  It
would not affect the Hierachy in customized cases.

Property file users could set a message bundle in the following way:

log4j.categoryFactory=org.apache.log4j.DefaultCategoryFactory
log4j.factory.messageBundle=MyLocalizations

This would cause a classpath search for MyLocalizations.properties.  If
found, the resulting message bundle would be associated with the
DefaultCategoryFactory and set on each Category it created.

- Paul

Paul Glezen
IT Specialist
Software Services for WebSphere
818 539 3321


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


Re: Configuring message bundles with Categories

Posted by Ceki Gülcü <cg...@qos.ch>.
Hi Paul,

Since the resource bundle is a property of the category class and not the hierarchy, I would suggest setting it like the additivity property.

log4j.resourceBundle.foo.bar=some_resource_bundle_name

where foo.bar is a category. This syntax can be extended to the XML configurator as well. 

Does that sound reasonable? Regards, Ceki


At 12:03 29.07.2001 -0700, Paul Glezen wrote:
>A while back some people expressed a need for configuring message bundles
>with categories via property files or XML files (I can't remember which).
>It would be easy to provide this ability for XML configuration now that we
>use the Java Bean convention of configuration.
>
>For property files, because of the unique structure of the category line,
>this may not be possible the way things are now.  However, the next best
>thing would be to follow the manner in the appserver package whereby the
>message bundle is configured on the category factory instead of a
>particular category.  One misses the flexability of configuring a separate
>message bundle for each category, but for cases where a single message
>bundle suffices, it will do the job.
>
>This would require modification of DefaultCategoryFactory to accept a
>message bundle in its configuration - easy enough.  The sensitive part is
>how to associate the DefaultCategoryFactory to the Hierarchy.  There is a
>setCategoryFactory method on the Hierarchy class that I think is left over
>from when I was wanting to set custome category factories on the Hierarchy.
>Ceki was opposed to the idea of encouraging this kind of access to the the
>hierarchy at the time; so I did something different for the customized
>category case.
>
>I would like to propose modifying
>PropertyConfigurator.configureCategoryFactory(Properties) to set the
>Hierachy's default category factory whenever the factory is an instance of
>DefaultCategoryFactory.  This would allow DefaultCategoryFactory to be
>configured with a message bundle and associated with the Hierarchy.  It
>would not affect the Hierachy in customized cases.
>
>Property file users could set a message bundle in the following way:
>
>log4j.categoryFactory=org.apache.log4j.DefaultCategoryFactory
>log4j.factory.messageBundle=MyLocalizations
>
>This would cause a classpath search for MyLocalizations.properties.  If
>found, the resulting message bundle would be associated with the
>DefaultCategoryFactory and set on each Category it created.
>
>- Paul
>
>Paul Glezen
>IT Specialist
>Software Services for WebSphere
>818 539 3321
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

--
Ceki Gülcü - http://qos.ch


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