First thing the use of classes as category names is a convention.  You can
use anything you want to as I added the .user and .system to the end of the
class name.

Second the code in your post looks like it will work.

Here is the config file I used to test the idea.

# Set root category priority to FATAL and its appender to A1.
log4j.rootCategory=FATAL, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

#category com.bjsscrapbooks.logging.MultipleCategories.user priority INFO and use 
appender UserFile
log4j.category.com.bjsscrapbooks.logging.MultipleCategories.user=INFO, UserFile
log4j.additivity.com.bjsscrapbooks.logging.MultipleCategories.user=false

#category com.bjsscrapbooks.logging.MultipleCategories.system priority ERROR and use 
appender SystemFile
log4j.category.com.bjsscrapbooks.logging.MultipleCategories.system=ERROR, SystemFile
log4j.additivity.com.bjsscrapbooks.logging.MultipleCategories.system=false

#UserFile appender for user messages
log4j.appender.UserFile=org.apache.log4j.FileAppender
log4j.appender.UserFile.layout=org.apache.log4j.PatternLayout
log4j.appender.UserFile.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.appender.UserFile.file=user.log

#SystemFile appender for system messages
log4j.appender.SystemFile=org.apache.log4j.FileAppender
log4j.appender.SystemFile.layout=org.apache.log4j.PatternLayout
log4j.appender.SystemFile.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.appender.SystemFile.file=system.log

I use Category com.bjsscrapbooks.logging.MultipleCategories.user and
com.bjsscrapbooks.logging.MultipleCategories.system  I turned additivity
off because only wanted the output to go to the files.

when I run a test program that sends a message to both user and system for
each priority I only get INFO and above in the user file.  In the System
file I get ERROR and above.

Mark Russell
PNC
412-768-9603


                                                                                       
                          
                    "Sam Newman"                                                       
                          
                    <sam.newman@stam        To:     "LOG4J Users Mailing List" 
<[EMAIL PROTECTED]>   
                    plets.com>              cc:                                        
                          
                                            Subject:     Re: Multiple Appenders        
                          
                    07/25/2001 10:07                                                   
                          
                    AM                                                                 
                          
                    Please respond                                                     
                          
                    to "LOG4J Users                                                    
                          
                    Mailing List"                                                      
                          
                                                                                       
                          
                                                                                       
                          



Currently I use log4j via an abstracted static class. I have a method
called
warn, which does the following (it is a little aprroximated - don't have
the
code in from of me):

public void warn(Class class, String message) {
  Category cat = Category.getInstance(class.getName());
  cat.warn(message);
}

The Category and its appenders are created in the static classes
getInstance
method by using a PropertyConfigurator. Now for me to extend this idea to
use system and user warnings, from what your saying I'd do the following:

public void systemWarn(Class class, String message) {
  Category cat = Category.getInstance(class.getName()+".system");
  cat.warn(message);
}



public void userWarn(Class class, String message) {
  Category cat = Category.getInstance(class.getName()+".user");
  cat.warn(message);
}

However, I'm unsure how this would work - surely the getInstance method
will
try and find a category for a class (assuming I called userWarn() for a
class in com.bob.MyClass) com.bob.MyClass.user (e.g. a non-existing class).
So when configuring my Category initially using the property file, how
would
I create my Category to match this when getInstance is called?

Sorry if my question doesn't make much sense.....

sam
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "LOG4J Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, July 25, 2001 1:31 PM
Subject: Re: Multiple Appenders


>
> How about using two categories
> Category catUser = Category.getInstance(className.class.getName() +
> ".user");
> Category catSystem = Category.getInstance(className.class.getName() +
> ".system");
>
> Then you could set different appenders to the different categories.
> You could log user events like this:
> catUser.info("this is a user message");
> and system events:
> catSystem.info("this is a system event");
>
> my2cents
> Mark Russell
> PNC
> 412-768-9603



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






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

Reply via email to