Title: AW: [beginner] How to send logs to different Appenders?
Hi,
I send you the code as it is. It sends output from the first appender
to the console and the second appender to file:
 
 import com.foo.Bar;
 
 import org.apache.log4j.Category;
 import org.apache.log4j.PropertyConfigurator;
 
 public class MyApp {
 
   static Category cat = Category.getInstance(MyApp.class.getName());
 
   public static void main(String[] args) {
 

     // BasicConfigurator replaced with PropertyConfigurator.
     PropertyConfigurator.configure("log.properties");
 
     cat.info("Entering application.");
     Bar bar = new Bar();
     bar.doIt();
     cat.info("Exiting application.");
     cat.shutdown();
   }
 }
 
 package com.foo;
 import org.apache.log4j.Category;
 
 public class Bar {
   static Category cat = Category.getInstance(Bar.class);
 
   public void doIt() {
     cat.warn("Did it again!");
   }
 }
 
 
******File: log.properties
 
 
log4j.rootCategory=DEBUG
 
log4j.category.MyApp=INHERITED,A1
log4j.category.com.foo=INHERITED,A2
 
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
 
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=server.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=[%c{1}] %m%n
log4j.appender.A2.Append=false
 
it should work, try it.
Francesco
 
 
 
# Print the date in ISO 8601 format
 
# Print only messages of priority WARN or above in the package com.foo.
 
 
----- Original Message -----
Sent: Friday, August 31, 2001 12:10 PM
Subject: AW: [beginner] How to send logs to different Appenders?

I'm followed this conversation step by step and am still not able to write those 3 lines of code :-) write


log4j.rootCategory=INFO
log4j.category.ufa=DEBUG, A2
log4j.category.ufa=INHERITED, A1


The name of the root-Package ist ufa

A1 writes to the standard-output -> works fine
A2 writes in a file -> works fine

I want all messages with priority DEBUG or higher  in the file
I want all messages with priority INFO or higher  on the standard-output

Is anybody out there how tells me, what I am doing wrong ?(I have read the manual, but my englisch is not yet perfect...)


Mit freundlichen Grüssen

Beat Friedli

------------------------------------------------------------------------------
UFA AG
Hofmattstrasse 40
3360 Herzogenbuchsee
Tel: ++41 62 956 63 94

email: <mailto:[EMAIL PROTECTED]>
homepage: <http://www.ufa.ch
homepage: <http://www.hypona.ch>


-----Ursprüngliche Nachricht-----
Von: Jon Skeet [mailto:[EMAIL PROTECTED]]
Gesendet: Donnerstag, 30. August 2001 16:52
An: LOG4J Users Mailing List
Betreff: RE: [beginner] How to send logs to different Appenders?


> Hi Jon.....so I have tried to modify my lo4j.properties of
> the basic example
> that comes with distribution.
> That's what I'd like to obtain:
>
> Class  MyApp----------->Console Appender
> Class  com.foo.Bar------>File Appender
>
> Here's how I have structured my log4j.properties:
>
> log4j.rootCategory=DEBUG,A1,A2

This is the problem - you're saying that *all* categories should be
appended to A1 *and* A2.

Change that to

log4j.rootCategory=DEBUG

and everything should be okay (I think :)

> log4j.category.MyApp=A1
> log4j.category.com.foo=A2

Ah - not quite. You need an INHERITED in the above (before the A1 or A2)
to say that the priority is the inherited one - otherwise it'll assume
DEBUG (I believe).

Jon

---------------------------------------------------------------------
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