I would hazard a guess that you haven't read much of the material available
on how to use log4j. Loggers inherit their behavior from a runtime hierarchy
based on their names. java.util is the parent of java.util.foo and java.util
is an ancestor of java.util.foo.bar where those dot separated names are
names of loggers, paramters passed to Logger.getLogger(). Each logger can be
configured with different appenders and all kinds of stuff. An appender
knows where its output goes. If your client and your service reside in
different packages, as one would hope they might, setting them up to log to
different log files is as simple as setting them up with different
appenders. Say you have com.rob.client.foo and com.rob.service.bar. By
establishing loggers in your properties file for com.rob.client and
com.rob.service, classes from those two packages down to the root (i.e.,
com.rob.service.bar.ClassA and com.rob.client.ClassB) will log to different
logfiles if you configure them with different appenders.
In your properties file, set up as follows:

log4j.logger.com.rob.service=WARN, A2
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.file=log/service.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.logger.com.rob.client=WARN, A3
log4j.appender.A3=org.apache.log4j.RollingFileAppender
log4j.appender.A3.file=log/client.log
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

That's about it.
Rich

-----Original Message-----
From: Robert Mark Bram [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 07, 2002 6:29 AM
To: Log4J Users List
Subject: RE: options and different loggers


Howdy Richard!

> It means .. <snip>
> Does that help?

Yes it does, thank you - may I press you for some further help with my
second question?

>
> I am constructing a Jini application - I will have a client and
> service that
> will (in the completed application) reside on different machines. For now,
> however, they will both run on the same machine, but from within different
> JVM's (communicating via RMI).
>
> How can I make them create different log files?
>
> Should I create different log4j.properties files?
>
> These are the primary configurations I have set in my properties file:
>
> # I don't know what this one means
> log4j.rootLogger=DEBUG, A1
>
> # Sets the primary handler to be one that writes to a file
> log4j.appender.A1=org.apache.log4j.FileAppender
>
> # Sets the primary handler to be one that writes html output
> log4j.appender.A1.layout=org.apache.log4j.HTMLLayout
>


Thanks!

Rob

:)
:-}
;->


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


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

Reply via email to