You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Yuriy Larin <ze...@nixsolutions.com> on 2001/07/04 17:03:54 UTC
How to attach Appender to my own category ?
Hi.
Just a pretty simple question, but I can't do it. :(
I have that in a source file.
======
package com.nix.example;
........
MyCategory c = (MyCategory) MyCategory.getInstance("D.I.Subsystem");
c.info("XXXX");
c.error("CCCC");
........
======
There are config file.
------------------
log4j.rootCategory=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
..........
Now I want to have another one for my category.
?? D.I.Subsystem=DEBUG, A2
?? com.nix.example.MyCategory=DEBUG, A2
What is right way to get it ? I've tried both but I can't get a result in
the "test.log" file. What's wrong ?
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=test.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{3} - %m%n
Thanks in advance.
Yuriy.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: How to attach Appender to my own category ?
Posted by Paul Glezen <pg...@atdial.net>.
Yuriy Larin wrote:
>
> Sorry for mistake (how to specify category in the XML) I meant "to specify
> CategoryFactory in XML".
>
That's what I meant too.
> Unfortunatly I didn't find examples. (log4j 1.1.3) :(((
>
Check out the package documentation for
org.apache.log4j.examples.appserver.
Once again, this was updated mid-June, so you need a recent copy.
- Paul
--
Beware of bugs in the above code. I have
only proved it correct, not tried it.
-Don Knuth
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: How to attach Appender to my own category ?
Posted by Yuriy Larin <ze...@nixsolutions.com>.
Thank you Paul for fast answers.
> > > You can do this in at least two ways.
> > > 1. Safe but more work
> > > Create a factory for your category. Specify the factory in your
> > > configuration file.
> > Am I wrong ?
> The option is there in the DTD; but it is a new one that you might not
> have yet. It was placed there in June.
Sorry for mistake (how to specify category in the XML) I meant "to specify
CategoryFactory in XML".
> > Should I write several factory classes for every my subsystem's type or
can
> > I use only one ?
> >
> I assume by "hierarchies (categories with subcategories)" you mean
> several different subclasses of the Category type.
yes
> Only with the XML
> cofiguration can you specify which category gets creaed by which factory
> at configuration time.
Unfortunatly I didn't find examples. (log4j 1.1.3) :(((
> If you use property configuration, the last
> factory configured creates the categories.
Ok..
- Yuriy.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: How to attach Appender to my own category ?
Posted by Paul Glezen <pg...@atdial.net>.
Yuriy Larin wrote:
>
> Thank you Paul.
>
> > You can do this in at least two ways.
> > 1. Safe but more work
> > Create a factory for your category. Specify the factory in your
> > configuration file.
> I see. But... how to specify category in the XML configuration file? I need
> store it in the XML. Unfortunatly I don't see this ability in the log4j.dtd.
> Am I wrong ?
>
The option is there in the DTD; but it is a new one that you might not
have yet. It was placed there in June.
> > All newly created categories will use this factory
> > and hence be of the sub category type.
> One more question, pls.
> If I want to have several hierarchies (categories with subcategories) in my
> system for logging, e.g. - D.I.Subs1, D.I.Subs2...., PRN.Subs1,
> PRNSubs2....etc..
> Should I write several factory classes for every my subsystem's type or can
> I use only one ?
>
I assume by "hierarchies (categories with subcategories)" you mean
several different subclasses of the Category type. Only with the XML
cofiguration can you specify which category gets creaed by which factory
at configuration time. If you use property configuration, the last
factory configured creates the categories.
- Paul
--
Beware of bugs in the above code. I have
only proved it correct, not tried it.
-Don Knuth
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: How to attach Appender to my own category ?
Posted by Yuriy Larin <ze...@nixsolutions.com>.
Thank you Paul.
> You can do this in at least two ways.
> 1. Safe but more work
> Create a factory for your category. Specify the factory in your
> configuration file.
I see. But... how to specify category in the XML configuration file? I need
store it in the XML. Unfortunatly I don't see this ability in the log4j.dtd.
Am I wrong ?
> All newly created categories will use this factory
> and hence be of the sub category type.
One more question, pls.
If I want to have several hierarchies (categories with subcategories) in my
system for logging, e.g. - D.I.Subs1, D.I.Subs2...., PRN.Subs1,
PRNSubs2....etc..
Should I write several factory classes for every my subsystem's type or can
I use only one ?
Yuriy.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: How to attach Appender to my own category ?
Posted by Paul Glezen <pg...@atdial.net>.
Yuriy Larin wrote:
>
> Hi.
>
> Just a pretty simple question, but I can't do it. :(
>
> I have that in a source file.
> ======
> package com.nix.example;
> ........
> MyCategory c = (MyCategory) MyCategory.getInstance("D.I.Subsystem");
> c.info("XXXX");
> c.error("CCCC");
> ........
> ======
>
> There are config file.
> ------------------
> log4j.rootCategory=DEBUG, A1
> log4j.appender.A1=org.apache.log4j.ConsoleAppender
> ..........
>
> Now I want to have another one for my category.
> ?? D.I.Subsystem=DEBUG, A2
> ?? com.nix.example.MyCategory=DEBUG, A2
>
> What is right way to get it ? I've tried both but I can't get a result in
> the "test.log" file. What's wrong ?
>
You can do this in at least two ways.
1. Safe but more work
Create a factory for your category. Specify the factory in your
configuration file. All newly created categories will use this factory
and hence be of the sub category type.
2. Quick but prone to error
Configure a category called "D.I". The PropertyConfigurator will create
a Category instance for "D.I". In your code you create a MyCategory
instance with name "D.I.Subsystem". MyCategory "D.I.Subsystem" will
inherit the appender from the Category "D.I". You won't actually log
anything to the "D.I" Category.
The "prone to error" disclaimer results from the possibility that later
you might want to create a MyCategory named "D.I". Actually, you will
only get the base class instance "Category" created during the
configuration.
- Paul
--
Beware of bugs in the above code. I have
only proved it correct, not tried it.
-Don Knuth
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org