You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Jason Wong <zx...@live.com> on 2011/09/28 23:45:31 UTC

Getting duplicated logging in console log

I am trying to modify the runtime behavior on the log4j.

Here is my implementation: 

public static Logger getLogger(Class c) {
		
		Logger logger = Logger.getLogger(c);
                         String pattern = "%d{dd-MMM-yyyy HH:mm:ss,SSS} %p
%c{3} (%M:%L)- %m%n";
		
		PatternLayout layout = new PatternLayout(pattern);
		ConsoleAppender appender = new ConsoleAppender(layout);
		
		logger.addAppender(appender);
	             return logger;
	}

The caller is showed as beloew:

static Logger logger = AccountAccessUtil.getLogger(Domain.class);

However I am getting the following:
28-Sep-2011 16:43:22,777 DEBUG plugin.retailCustomer.Domain
(enrichedQuery:113)- ** lalalala **
2011-09-28 16:43:22,777 | main | DEBUG | plugin.retailCustomer.Domain | **
lalalala **

Is there anyway that I can get rid of second logging? Please note that I
have no control on log4j.properties file.

thanks,

Jason
-- 
View this message in context: http://old.nabble.com/Getting-duplicated-logging-in-console-log-tp32549974p32549974.html
Sent from the Log4j - Dev mailing list archive at Nabble.com.


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


Re: Getting duplicated logging in console log

Posted by Jacob Kjome <ho...@visi.com>.
Don't manually add an appender in application code.  That what the config file 
is for.  Besides, every time your static getLogger(Class) method is called, 
you will add one more appender and will get an additional duplicate message 
for every new appender you add.

Jake

On Wed, 28 Sep 2011 14:45:31 -0700 (PDT)
 Jason Wong <zx...@live.com> wrote:
> 
> I am trying to modify the runtime behavior on the log4j.
> 
> Here is my implementation: 
> 
> public static Logger getLogger(Class c) {
> 		
> 		Logger logger = Logger.getLogger(c);
>                         String pattern = "%d{dd-MMM-yyyy HH:mm:ss,SSS} %p
> %c{3} (%M:%L)- %m%n";
> 		
> 		PatternLayout layout = new PatternLayout(pattern);
> 		ConsoleAppender appender = new ConsoleAppender(layout);
> 		
> 		logger.addAppender(appender);
> 	             return logger;
> 	}
> 
> The caller is showed as beloew:
> 
> static Logger logger = AccountAccessUtil.getLogger(Domain.class);
> 
> However I am getting the following:
> 28-Sep-2011 16:43:22,777 DEBUG plugin.retailCustomer.Domain
> (enrichedQuery:113)- ** lalalala **
> 2011-09-28 16:43:22,777 | main | DEBUG | plugin.retailCustomer.Domain | **
> lalalala **
> 
> Is there anyway that I can get rid of second logging? Please note that I
> have no control on log4j.properties file.
> 
> thanks,
> 
> Jason
> -- 
> View this message in context: 
>http://old.nabble.com/Getting-duplicated-logging-in-console-log-tp32549974p32549974.html
> Sent from the Log4j - Dev mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 
> 


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