logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Berwanger, Christian" <christian.berwan...@logica.com>
Subject RE: Syslog message is sent twice in the case no log4j configuration file is used
Date Wed, 09 Jul 2008 15:27:00 GMT
Thx Heri for answering!

Following code unfortunately produces the same problem. I still receive
the message twice. 

m_logger = Logger.getRootLogger();
m_logger.setAdditivity(false);
m_syslogAppender = new SyslogAppender();
m_syslogAppender.activateOptions();
m_syslogAppender.setLayout(new PatternLayout("%c: %m%n"));
m_syslogAppender.setSyslogHost("localhost");
m_logger.addAppender(m_syslogAppender);
m_syslogAppender.setFacility(mapFacilityID(this.m_facility));
sendLogMessage(logMessage);
m_logger.removeAllAppenders();


The only thing what I could imagine is that in the case there is no
configuration file defined the system automatically generates a standard
configuration with a standard syslog appender. To avoid this I tried to
set the Additivity to false. 

I also called the "getAllAppenders()" in order to count the added
appenders but I only got the right number of one!

Has somebody any other ideas?

Christian

-----Original Message-----
From: Bender Heri [mailto:HBender@Ergonomics.ch] 
Sent: Mittwoch, 9. Juli 2008 15:59
To: Log4J Users List
Subject: RE: Syslog message is sent twice in the case no log4j
configuration file is used

My only guess is that setting the additivity flag by code does not have
any effect. Or maybe a kind of activateOptions() on the logger must be
performed.

Why dont you fetch the RootLogger for appending your syslog appender, as
you do in your config example? After the log call you clear the
appenders anyway.

Heri 

> -----Original Message-----
> From: Berwanger, Christian [mailto:christian.berwanger@logica.com] 
> Sent: Wednesday, July 09, 2008 9:27 AM
> To: Log4J Users List
> Subject: RE: Syslog message is sent twice in the case no 
> log4j configuration file is used
> 
> Nobody has an idea?
> 
> -----Original Message-----
> From: Berwanger, Christian [mailto:christian.berwanger@logica.com]
> Sent: Dienstag, 8. Juli 2008 12:15
> To: log4j-user@logging.apache.org
> Subject: Syslog message is sent twice in the case no log4j 
> configuration file is used
> 
> Hi log4j comunity,
> 
>  
> 
> I'm using the log4j appender in order to send my log message 
> to a remote host. I decided not to use the config file 
> because the application itself is already using a central 
> config file which I want to use to read my configurable data 
> (like hostname, port...). However when I'm using the log4j 
> API without config file the message is sent twice times.
> 
>  
> 
> I read and tried already the hints on the tutorial sites 
> without success which threads several ideas for the problem 
> of multiple same messages. 
> 
>  
> 
>  m_logger = Logger.getLogger(SecurityEvent.class.getName());
> 
>  m_logger.setAdditivity(false);
> 
>  m_syslogAppender = new SyslogAppender();
> 
>  m_syslogAppender.activateOptions();
> 
>  m_syslogAppender.setLayout(new PatternLayout("%c: %m%n"));
> 
>  m_syslogAppender.setSyslogHost("localhost");
> 
>  m_logger.addAppender(m_syslogAppender);
> 
>  m_syslogAppender.setFacility(mapFacilityID(this.m_facility));
> 
>  sendLogMessage(logMessage);
> 
>  m_logger.removeAllAppenders();
> 
>  
> 
> However when I tried following configuration file instead it 
> worked fine.
> 
>  
> 
> # Set root logger level to DEBUG and its only appender to A1.
> 
> log4j.rootLogger=DEBUG, A1
> 
>  
> 
> # A1 is set to be a ConsoleAppender.
> 
> log4j.appender.A1=org.apache.log4j.net.SyslogAppender
> 
>  
> 
> # A1 uses PatternLayout.
> 
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> 
> log4j.appender.A1.SyslogHost=localhost
> 
>  
> 
> log4j.appender.A1.layout.ConversionPattern=%c: %m%n
> 
>  
> 
>  
> 
> How can I get only ONE log message?
> 
>  
> 
> Thanks for all help
> 
>  
> 
> Christian
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 
> 
> This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, 
> confidential information and/or be subject to legal 
> privilege. It should not be copied, disclosed to, retained or 
> used by, any other party. If you are not an intended 
> recipient then please promptly delete this e-mail and any 
> attachment and all copies and inform the sender. Thank you.
> 
> 
> This e-mail and any attachment is for authorised use by the 
> intended recipient(s) only. It may contain proprietary 
> material, confidential information and/or be subject to legal 
> privilege. It should not be copied, disclosed to, retained or 
> used by, any other party. If you are not an intended 
> recipient then please promptly delete this e-mail and any 
> attachment and all copies and inform the sender. Thank you.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 

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



This e-mail and any attachment is for authorised use by the intended recipient(s) only. It
may contain proprietary material, confidential information and/or be subject to legal privilege.
It should not be copied, disclosed to, retained or used by, any other party. If you are not
an intended recipient then please promptly delete this e-mail and any attachment and all copies
and inform the sender. Thank you.



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


Mime
View raw message