You can configure your entire logging system via a single config file.  You are not limited to one logger/appender per config file.  Besides, children of the the logger inherit from the parent, by default, so when you configure a given logger, e.g., the root logger, that same config applies to all children (unless you set additivity to false at some point in the hierarchy).  I assure you, there is no need for multiple config files.

The manual [1] shows examples of properties config files.  The wiki [2] provides examples of XML config files.  And any search engine will provide lots of extra resources showing how to write Log4j config files.  Please read these resources and take a crack at the config.  Feel free to post your config if you have more questions.


[1] http://logging.apache.org/log4j/1.2/manual.html
[2] http://wiki.apache.org/logging-log4j/Log4jXmlFormat

Jake


On Wed, 8 Dec 2010 09:35:28 -0800 (PST)
 Refr Bruhl <refr_br...@yahoo.com> wrote:
Well been doing that already.

Lets start with the basics
What is the syntax for configuring multiple loggers using an xml file?

If I use log4j.xml or log4j.properties I can configure one logger with code straight from a tutorial... org.apache.log4j.Logger conLogger = Logger.getLogger(BaseConfig.class);


Using this as a model I would think I would want
org.apache.log4j.Logger qryLogger = Logger.getLogger(BaseConfig.class); org.apache.log4j.Logger lgLogger = Logger.getLogger(BaseConfig.class); org.apache.log4j.Logger exLogger = Logger.getLogger(BaseConfig.class);

Yet if I use this construct, even if I set loggers in the xml file, the last defined file will write console output to its log.

So it seems to me that instead of basing a logger on a class, I need to base a logger on a unique xml file.

I can use URL url = Loader.getResource("conLogger.xml");
     DOMConfigurator.configure(url);

again from the same tutorial.. but it only works with 1 xml file.


So if I am limited to 1 xml file how do I configure separate loggers and appenders in 1 xml file or is there a way I can have 4 separate xml files with a unique logger and appender for each?






--Refr inn gra


"Wars are to be won with swords and spears, not with rice and salt." -- Uesugi Kenshin




________________________________
From: Jacob Kjome <h...@visi.com>
To: Log4J Users List <log4j-user@logging.apache.org>
Sent: Wed, December 8, 2010 11:12:08 AM
Subject: Re: Log4j with multiple files converting to xml

I suggest that you take a crack at the configuration yourself. If you still have questions, post it and we can help you tweak it.

Jake


On Wed, 8 Dec 2010 08:16:44 -0800 (PST)
Refr Bruhl <refr_br...@yahoo.com> wrote:

Greetings

I tried searching for this on the mail archives link, the link seems to be changed.

My goal:
I have 4 files for logging. ConLogger -> logs to console, lgLogger -> logs to a log file, qryLogger that logs to a log file, delLogger that logs to a log file, and exLogger that logs to a log file

lgLogger logs generall aplication activity. I have used addAppender to ensure everything logged to the console is also logged to lgLogger
qryLogger logs nothing but query information
exLogger logs all exception errors

All 4 of these files can support debug thru fatal entries.

I have used this same pattern in several "batch" type jobs for about 4 years now.

These files are configured in the primary java class.

What I want to do is change the configuration from "hard" coding these log files in the app to using xml files for configuration.

The problem I am running into is it seems when using xml or property files log4j makes the assumption of only one logger with multiple appenders per xml file. I want or think I want 4 distinct loggers with each having a separate appender.

Is this correct? Has anyone else tried to do something similar with log4j? Any idea on how to achieve this?


Thanks!


--Refr inn gra


"Wars are to be won with swords and spears, not with rice and salt." -- Uesugi Kenshin





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to