Hi,

after a long search on the internet, I have managed to do what I wanted: define multiple loggers.
If it can help anybody, the solution to my problem was only to write this line in log4j.properties:
log4j.logger.fraLogger = ERROR, ACSALogger2
instead of this line:
log4j.fraLogger = ERROR, ACSALogger2
now, I can have more than one logger each writing to its own file.
Regards

Francois


Francois MAROT wrote:
Hi,
and first of all, thanks for your quick responses.
But I still can't get it to work !     :(
In c++:
PropertyConfigurator::configure("log4j.properties");
LoggerPtr fraLogger = Logger::getLogger("fraLogger");

In log4j.properties:
log4j.rootLogger = DEBUG, ACSALogger
log4j.appender.ACSALogger = org.apache.log4j.RollingFileAppender
log4j.appender.ACSALogger.layout = org.apache.log4j.PatternLayout
log4j.appender.ACSALogger.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.appender.ACSALogger.File = ACSALogger.log
log4j.appender.ACSALogger.MaxFileSize=1KB

log4j.fraLogger = ERROR, ACSALogger2
log4j.additivity.fraLogger=false
log4j.appender.ACSALogger2 = org.apache.log4j.RollingFileAppender
log4j.appender.ACSALogger2.layout = org.apache.log4j.SimpleLayout
log4j.appender.ACSALogger2.File = TMP.log

The problem is that everything logged goes to ACSALogger.log and not to TMP.log.
TMP.log receives data only if I tell rootlogger to use ACSALogger2 too as a logger. The first line becomes :
log4j.rootLogger = DEBUG, ACSALogger,  ACSALogger2.
The point is i'd like to have differents loggers for different parts of the software.
Any more advice from you log4cxx users ?

Regards

Francois


Francois MAROT wrote:



Subject:
Re: Newbie question
From:
Curt Arnold <[EMAIL PROTECTED]>
Date:
Mon, 27 Feb 2006 14:06:41 -0600
To:
Log4CXX User <[email protected]>
To:
Log4CXX User <[email protected]>


On Feb 27, 2006, at 9:36 AM, Francois MAROT wrote:

Hi all,

i'm about to implement a logging system and have been experimenting with log4cxx recently. But i have some problems...
The fact is I don't try to do anything very hard, only configuring properly my output to a desired file.
I thought, as i stated in code i wanted to use logger "log4j.fraLogger", that my logging info would be written
in the file named "TMP.log". But it is written in file "ACSA-log4cxx.log". I thought only rootlogger would
write to this file... Am I missing something ?


Looks like two things, one you are logging to "log4j.fraLogger" in the code, but are configuring "fraLogger" in the properties file.  The "log4j." in the properties file just identifies the property as pertaining to log4j configuration and is discarded.  If you change the argument in the getLogger call from "log4j.fraLogger" to "fraLogger", your log requests should go into both ACSA-log4cxx.log and TMP.log.

As mentioned in the previous message, if you do not want messages to go to both files, you need to specify the "additivity" for the fraLogger to false so that it does not pass on the requests to appenders attached to the root.  You would do that by adding the following line to your configuration file.


log4j.additivity.fraLogger=false

Reply via email to