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 Tim Watts <ti...@earthlink.net> on 2006/03/30 22:29:52 UTC

Double Logging

Hi,

Does anyone have an idea why all my log entries are posted twice in the log? 

Below is my configuration file and a tiny program the reproduces the problem. 
I'm using log4j version 1.2.8 and java version 1.4.2.

The other weird thing is that although the log level is set for INFO, only 
warn or greater gets logged. I turned log4j.debug on and verified that it's 
finding the correct file.  What's going on?

== begin cfg ===================================
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=WARN, CONSOLE, LOGFILE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE

log4j.logger.com.inxight=INFO, CONSOLE, LOGFILE
log4j.logger.org.apache=WARN, CONSOLE, LOGFILE
log4j.logger.servletunit=WARN, CONSOLE, LOGFILE

# Set the enterprise logger category to FATAL and its only appender to 
CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=WARN
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.LOGFILE.File=${user.home}/sdxadminui.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.MaxFileSize=5MB
log4j.appender.LOGFILE.MaxBackupIndex=1
log4j.appender.LOGFILE.Threshold=DEBUG
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
== end cfg ===================================

== begin pgm ===================================
package com.inxight.sdx.adminui;

import org.apache.log4j.Logger;

public class LogTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Logger logger = Logger.getLogger(LogTest.class);
        logger.warn("this is a test.");
    }

}
== end pgm===================================

== begin classpath ===================================
CLASSPATH=WebSite/WEB-INF/classes/
CLASSPATH=$CLASSPATH:bin
CLASSPATH=$CLASSPATH:WebSite/WEB-INF/lib/log4j-1.2.8.jar
export CLASSPATH
== end classpath ===================================

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


Re: Double Logging

Posted by Javier Gonzalez <ja...@gmail.com>.
The downside is that "errant" log messages won't reach any logs. An error in
some framework, for example. If you have specified
appenders for every "branch" of your logger hierachy, there should be no
problem. However, insuring that isn't easy.

Usually I leave the root logger at WARN level, and for the loggers that like
to spit a lot of info I disable additivity.

On 3/30/06, Tim Watts <ti...@earthlink.net> wrote:
>
> On Thursday 30 March 2006 15:44, Javier Gonzalez wrote:
> > A way to fix this is to
> > set additivity in your loggers to false. The other one is to implement
> your
> > appenders with additivity in mind.
>
> Thanks for the quick response. A third way is to comment out the
> rootCategory.
> What's the down-side to that?
>
> >
> > > The other weird thing is that although the log level is set for INFO,
> > > only warn or greater gets logged. I turned log4j.debug on and verified
> > > that it's
> > > finding the correct file.  What's going on?
> >
> > I see your test code sends warn level messages - have you tried it with
> > logger.info(), logger.debug()?
> >
> > According to your config file, you should see Warn or higher at the
> > console, and all messages in the log file. Does this happen?
>
> Yes. I saw that after I sent the email. Thanks again for your time.
>
> >
> >
> > == begin cfg ===================================
> >
> > > # Set root category priority to INFO and its only appender to CONSOLE.
> > > log4j.rootCategory=WARN, CONSOLE, LOGFILE
> > > #log4j.rootCategory=INFO, CONSOLE, LOGFILE
> > >
> > > log4j.logger.com.inxight=INFO, CONSOLE, LOGFILE
> > > log4j.logger.org.apache=WARN, CONSOLE, LOGFILE
> > > log4j.logger.servletunit=WARN, CONSOLE, LOGFILE
> > >
> > > # Set the enterprise logger category to FATAL and its only appender to
> > > CONSOLE.
> > > log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
> > >
> > > # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
> > > log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
> > > log4j.appender.CONSOLE.Threshold=WARN
> > > log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
> > > log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
> > >
> > > # LOGFILE is set to be a File appender using a PatternLayout.
> > > log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
> > > log4j.appender.LOGFILE.File=${user.home}/sdxadminui.log
> > > log4j.appender.LOGFILE.Append=true
> > > log4j.appender.LOGFILE.MaxFileSize=5MB
> > > log4j.appender.LOGFILE.MaxBackupIndex=1
> > > log4j.appender.LOGFILE.Threshold=DEBUG
> > > log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
> > > log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x -
> %m%n
> > > == end cfg ===================================
> > >
> > > == begin pgm ===================================
> > > package com.inxight.sdx.adminui;
> > >
> > > import org.apache.log4j.Logger;
> > >
> > > public class LogTest {
> > >
> > >     /**
> > >      * @param args
> > >      */
> > >     public static void main(String[] args) {
> > >         Logger logger = Logger.getLogger(LogTest.class);
> > >         logger.warn("this is a test.");
> > >     }
> > >
> > > }
> > > == end pgm===================================
> > >
> > > == begin classpath ===================================
> > > CLASSPATH=WebSite/WEB-INF/classes/
> > > CLASSPATH=$CLASSPATH:bin
> > > CLASSPATH=$CLASSPATH:WebSite/WEB-INF/lib/log4j-1.2.8.jar
> > > export CLASSPATH
> > > == end classpath ===================================
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> > --
> > Javier González Nicolini
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


--
Javier González Nicolini

Re: Double Logging

Posted by Tim Watts <ti...@earthlink.net>.
On Thursday 30 March 2006 15:44, Javier Gonzalez wrote:
> A way to fix this is to
> set additivity in your loggers to false. The other one is to implement your
> appenders with additivity in mind.

Thanks for the quick response. A third way is to comment out the rootCategory. 
What's the down-side to that?

>
> > The other weird thing is that although the log level is set for INFO,
> > only warn or greater gets logged. I turned log4j.debug on and verified
> > that it's
> > finding the correct file.  What's going on?
>
> I see your test code sends warn level messages - have you tried it with
> logger.info(), logger.debug()?
>
> According to your config file, you should see Warn or higher at the
> console, and all messages in the log file. Does this happen?

Yes. I saw that after I sent the email. Thanks again for your time.

>
>
> == begin cfg ===================================
>
> > # Set root category priority to INFO and its only appender to CONSOLE.
> > log4j.rootCategory=WARN, CONSOLE, LOGFILE
> > #log4j.rootCategory=INFO, CONSOLE, LOGFILE
> >
> > log4j.logger.com.inxight=INFO, CONSOLE, LOGFILE
> > log4j.logger.org.apache=WARN, CONSOLE, LOGFILE
> > log4j.logger.servletunit=WARN, CONSOLE, LOGFILE
> >
> > # Set the enterprise logger category to FATAL and its only appender to
> > CONSOLE.
> > log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
> >
> > # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
> > log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
> > log4j.appender.CONSOLE.Threshold=WARN
> > log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
> > log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
> >
> > # LOGFILE is set to be a File appender using a PatternLayout.
> > log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
> > log4j.appender.LOGFILE.File=${user.home}/sdxadminui.log
> > log4j.appender.LOGFILE.Append=true
> > log4j.appender.LOGFILE.MaxFileSize=5MB
> > log4j.appender.LOGFILE.MaxBackupIndex=1
> > log4j.appender.LOGFILE.Threshold=DEBUG
> > log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
> > log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
> > == end cfg ===================================
> >
> > == begin pgm ===================================
> > package com.inxight.sdx.adminui;
> >
> > import org.apache.log4j.Logger;
> >
> > public class LogTest {
> >
> >     /**
> >      * @param args
> >      */
> >     public static void main(String[] args) {
> >         Logger logger = Logger.getLogger(LogTest.class);
> >         logger.warn("this is a test.");
> >     }
> >
> > }
> > == end pgm===================================
> >
> > == begin classpath ===================================
> > CLASSPATH=WebSite/WEB-INF/classes/
> > CLASSPATH=$CLASSPATH:bin
> > CLASSPATH=$CLASSPATH:WebSite/WEB-INF/lib/log4j-1.2.8.jar
> > export CLASSPATH
> > == end classpath ===================================
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
>
> --
> Javier González Nicolini

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


Re: Double Logging

Posted by Javier Gonzalez <ja...@gmail.com>.
On 3/30/06, Tim Watts <ti...@earthlink.net> wrote:
>
> Hi,
>
> Does anyone have an idea why all my log entries are posted twice in the
> log?



It looks like you attached your appenders twice - once for the root logger
and once for a specific logger. Since you haven't turned off additivity in
any logger, every log event that happens at, say, com.inxight.* gets sent to
the Console and Logfile appenders, and THEN, since its additivity is on, the
same event gets relayed up the hierachy until it reaches the root logger.
Since the root logger has the appenders Console and Logfile appenders
attached, you see the log events twice. A way to fix this is to set
additivity in your loggers to false. The other one is to implement your
appenders with additivity in mind.



> The other weird thing is that although the log level is set for INFO, only
> warn or greater gets logged. I turned log4j.debug on and verified that
> it's
> finding the correct file.  What's going on?


I see your test code sends warn level messages - have you tried it with
logger.info(), logger.debug()?

According to your config file, you should see Warn or higher at the console,
and all messages in the log file. Does this happen?


== begin cfg ===================================
> # Set root category priority to INFO and its only appender to CONSOLE.
> log4j.rootCategory=WARN, CONSOLE, LOGFILE
> #log4j.rootCategory=INFO, CONSOLE, LOGFILE
>
> log4j.logger.com.inxight=INFO, CONSOLE, LOGFILE
> log4j.logger.org.apache=WARN, CONSOLE, LOGFILE
> log4j.logger.servletunit=WARN, CONSOLE, LOGFILE
>
> # Set the enterprise logger category to FATAL and its only appender to
> CONSOLE.
> log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
>
> # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
> log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
> log4j.appender.CONSOLE.Threshold=WARN
> log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
> log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
>
> # LOGFILE is set to be a File appender using a PatternLayout.
> log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
> log4j.appender.LOGFILE.File=${user.home}/sdxadminui.log
> log4j.appender.LOGFILE.Append=true
> log4j.appender.LOGFILE.MaxFileSize=5MB
> log4j.appender.LOGFILE.MaxBackupIndex=1
> log4j.appender.LOGFILE.Threshold=DEBUG
> log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
> log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
> == end cfg ===================================
>
> == begin pgm ===================================
> package com.inxight.sdx.adminui;
>
> import org.apache.log4j.Logger;
>
> public class LogTest {
>
>     /**
>      * @param args
>      */
>     public static void main(String[] args) {
>         Logger logger = Logger.getLogger(LogTest.class);
>         logger.warn("this is a test.");
>     }
>
> }
> == end pgm===================================
>
> == begin classpath ===================================
> CLASSPATH=WebSite/WEB-INF/classes/
> CLASSPATH=$CLASSPATH:bin
> CLASSPATH=$CLASSPATH:WebSite/WEB-INF/lib/log4j-1.2.8.jar
> export CLASSPATH
> == end classpath ===================================
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


--
Javier González Nicolini