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 Kawthar Bt M Sulaiman <mk...@maxis.com.my> on 2004/04/02 06:31:50 UTC
Another confusion: how to log multiple files.
Hi,
Another confusion I'm having is how to log multiple files...
This is what I had done:
1. In my App 1, I called Logger.getLogger("MO").
This should write to a file MO.log
2. In my App 2, I called Logger.getLogger("APP").
This should write to a file APP.log
3. In my log4j.properties:
log4j.rootCategory=debug, MO, APP
log4j.appender.MO=org.apache.og4j.DailyRollingFileAppender
log4j.appender.MO.File=MO.log
log4j.appender.APP=org.apache.og4j.DailyRollingFileAppender
log4j.appender.APP.File=APP.log
I know this is not the right way to do coz it's not working.
So how do I tell in my code to write into which file. All of these
are configured in one file. Do I need multiple log4j.properties file
for different app?
Thanks,
--Kawthar
Confidential information may be contained in this e-mail and any files transmitted with it ('Message'). If you are not the addressee indicated in this Message (or responsible for delivery of this Message to such person), you are hereby notified that any dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. In such a case, you should delete this Message immediately and advise the sender by return e-mail. Opinions, conclusions and other information in this Message that do not relate to the official business of Maxis shall be understood as neither given nor endorsed by Maxis.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Another confusion: how to log multiple files.
Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Fri, 2004-04-02 at 16:31, Kawthar Bt M Sulaiman wrote:
> Hi,
>
> Another confusion I'm having is how to log multiple files...
> This is what I had done:
>
> 1. In my App 1, I called Logger.getLogger("MO").
> This should write to a file MO.log
>
> 2. In my App 2, I called Logger.getLogger("APP").
> This should write to a file APP.log
I'm not sure you have grasped the concept of "categories".
When you write:
Logger log = Logger.getLogger("MO");
log.debug("a message");
what you are saying is not "here's some data to be routed to file "MO",
but:
here is a message about the topic of "MO"
Try this:
Logger dogLog = Logger.getLogger("opinions.dogs");
Logger catLog = Logger.getLogger("opinions.cats");
dogLog.info("I like dogs");
catLog.info("I hate cats");
The first statement logged is info about the *topic* of
opinions-about-dogs. The second statement is info about the *topic* of
opinions-about-cats.
The logging config file then says what to do with messages about
specific topics (aka "categories"). You might write messages about the
topic of dogs to a "dogfile.txt", and about cats to a "catfile.txt", or
you might dump all "opinion" messages together to one destination. Or
you may configure the root category only, which will control *all*
messages.
The parameter to the getLogger method is therefore *not* a "filename" or
a description of "where" you will log.
One common pattern in java is this:
Logger log = Logger.getLogger(this.getClass().getName());
log.info("I'm here");
this logs a message about the topic (aka category) "com.acme.Foo", or
whatever the current class happens to be called.
Hope this helps,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Another confusion: how to log multiple files.
Posted by Paul Smith <pa...@lawlex.com.au>.
> log4j.rootCategory=debug, MO, APP
>
> log4j.appender.MO=org.apache.og4j.DailyRollingFileAppender
> log4j.appender.MO.File=MO.log
>
> log4j.appender.APP=org.apache.og4j.DailyRollingFileAppender
> log4j.appender.APP.File=APP.log
This is what you want:
log4j.rootCategory=debug
log4j.logger.MO=debug, MO
log4j.logger.APP=debug, APP
log4j.appender.MO=org.apache.og4j.DailyRollingFileAppender
log4j.appender.MO.File=MO.log
log4j.appender.APP=org.apache.og4j.DailyRollingFileAppender
log4j.appender.APP.File=APP.log
Note that "category" and "logger" are interchangeable (so "rootLogger"
is the same as "rootCategory")
Paul
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org