You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Francois MAROT <fr...@laposte.net> on 2006/02/27 16:36:52 UTC

Newbie question

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.

here's my c++ code:

    PropertyConfigurator::configure("ACSA-log4cxx-DBG.properties");
    LoggerPtr fraLogger = Logger::getLogger("log4j.fraLogger");
    LOG4CXX_INFO(fraLogger, "1 - info");
    LOG4CXX_WARN(fraLogger, "2 - warn");
    LOG4CXX_ERROR(fraLogger, "3 - error");
    LOG4CXX_FATAL(fraLogger, "4 - fatal");


and here is my file ACSA-log4cxx-DBG.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 = ACSA-log4cxx.log

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

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 ?

Thanks


Francois

Re: Newbie question

Posted by Curt Arnold <ca...@apache.org>.
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