Kitching Simon wrote:
>
> Hi Jim,
>
> Nice to see there *are* people using custom
> Priorities .. I thought I was alone for a while!
>
> Just a few comments:
>
> (a)
> with this approach, the custom category needs
> to be used like this:
>
> TraceableCategory cat = (TraceableCategory)
> TraceableCategory.getInstance("catname");
> cat.trace("msg");
>
> ie a cast is needed. This is not a big deal,
> but is a minor nuisance
What I've done is define a method other than getInstance which returns
the appropriate subclass, e.g. getTrace below:
public class Trace extends Category {
public static Category getInstance(String name) {
return Category.getInstance(name, traceFactory);
}
public static Trace getTrace(String name) {
return (Trace) getInstance(name);
}
...
}
>
> (b)
> in your xml config file, you didn't specify a
> custom CategoryFactory. Doesn't this mean
> that the above cast to TraceableCategory
> will throw an exception, because the
> Category object was actually created as a
> normal org.apache.log4j.Category?
>
> Your example shows how to explicitly set
> the category class for root, but it isn't feasable
> to set an explicit category class for every
> category...
>
> I think it *might* be ok if you don't try to
> set any filtering level on categories in the
> config file, as then the only category created
> is the root category, but as soon as category-
> specific config features are specified, the
> Configurator needs to create the Category
> object, and will use the default factory unless
> an alternative "global" factory has been defined.
This is a pain but it's usually possible to avoid configuring the exact
Category that one is interested in, e.g. if your code needs a Trace
Category for com.example.foo.bar.MyClass then instead of configuring
MyClass you configure com.example.foo.bar. The config code will then
create a Category for that node in the hierarchy and your app code will
create a Trace object for com.example.foo.bar.MyClass.
A real solution would be to make it possible to specify the
CategoryFactory per category.
--
Anders Kristensen
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]