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 Ivan Linhares Martins <li...@gmail.com> on 2005/05/24 20:56:08 UTC

Messages in a Loop

Hi,

I´m using log4j version 1-3 alpha 6, working with Socket and File Appenders. 

I would like to know if i can prevent repeated messages generated in a
loop appearing in files or remote receivers only by configuring Log4j,
i.e. not writing additional code. Is it possible?

Thanks,
Ivan

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


Re: Messages in a Loop

Posted by Antoine TYNEVEZ <at...@patrimoine.com>.
Hi Ivan, 

I think you could do like this :

class A {

Logger loggerA = Logger.getLogger(A.class.getName());
boolean doLogging = true;

void loop {
   while (true) {
   // some logix  
   ...
   // some verification
   if (condition &amp;&amp; doLogging) {
      loggerA.error("xxx"); // error msg 
      doLogging = false;
   }  
   // sleep for a while...
  }


Hope it can help,

Antoine

Ivan Linhares Martins a écrit :

>James,
>
>It should work with any loop, like this:
>
>class A {
>
>Logger loggerA = Logger.getLogger(A.class.getName());
>
>void loop {
>   while (true) {
>   // some logix  
>   ...
>   // some verification
>   if (condition) {
>      loggerA.error("xxx"); // error msg 
>   }  
>   // sleep for a while...
>  }
>}
>
>the problem is I have this kind of behavior in many parts of my code,
>and I wanted this "error msg" printed only once while the condition is
>true, without creating additional conditional variables inside the
>code.
>
>is it possible to do it? 
>
>[]'s
>Ivan Linhares
>
>
>ps: I should try Aron solution as well, but it requires some extra coding too
>
>
>On 5/24/05, James Stauffer <st...@gmail.com> wrote:
>  
>
>>Any loop or one specific loop?  If it is one specific loop you could
>>configure the logger that it uses.
>>
>>On 5/24/05, Ivan Linhares Martins <li...@gmail.com> wrote:
>>    
>>
>>>Hi,
>>>
>>>I´m using log4j version 1-3 alpha 6, working with Socket and File Appenders.
>>>
>>>I would like to know if i can prevent repeated messages generated in a
>>>loop appearing in files or remote receivers only by configuring Log4j,
>>>i.e. not writing additional code. Is it possible?
>>>
>>>Thanks,
>>>Ivan
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>
>>>
>>>      
>>>
>>--
>>James Stauffer
>>Are you good? Take the test at http://www.livingwaters.com/good/
>>
>>    
>>
>
>
>  
>

-- 
Antoine Tynevez
Patrimoine Management & Technologie



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


Re: Messages in a Loop

Posted by Ivan Linhares Martins <li...@gmail.com>.
James,

It should work with any loop, like this:

class A {

Logger loggerA = Logger.getLogger(A.class.getName());

void loop {
   while (true) {
   // some logix  
   ...
   // some verification
   if (condition) {
      loggerA.error("xxx"); // error msg 
   }  
   // sleep for a while...
  }
}

the problem is I have this kind of behavior in many parts of my code,
and I wanted this "error msg" printed only once while the condition is
true, without creating additional conditional variables inside the
code.

is it possible to do it? 

[]'s
Ivan Linhares


ps: I should try Aron solution as well, but it requires some extra coding too


On 5/24/05, James Stauffer <st...@gmail.com> wrote:
> Any loop or one specific loop?  If it is one specific loop you could
> configure the logger that it uses.
> 
> On 5/24/05, Ivan Linhares Martins <li...@gmail.com> wrote:
> > Hi,
> >
> > I´m using log4j version 1-3 alpha 6, working with Socket and File Appenders.
> >
> > I would like to know if i can prevent repeated messages generated in a
> > loop appearing in files or remote receivers only by configuring Log4j,
> > i.e. not writing additional code. Is it possible?
> >
> > Thanks,
> > Ivan
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
> 
> 
> --
> James Stauffer
> Are you good? Take the test at http://www.livingwaters.com/good/
> 


-- 
Esta mensagem (incluindo arquivos anexos) contém informações
confidenciais, privilegiadas ou protegidas por lei. Ela é dirigida
exclusivamente ao seu destinatário que a empregará nos ditames legais.
Se você não é o destinatário desta mensagem, deve imediatamente
destruí-la e advertir o remetente do erro de envio e a destruição da
mensagem. Qualquer divulgação, utilização, disseminação ou reprodução
(total ou parcial) desta mensagem ou das informações nela contidas é
proibida e sujeitará as sanções criminais a que incorrer, sem prejuízo
de perdas e danos.

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


Re: Messages in a Loop

Posted by James Stauffer <st...@gmail.com>.
Any loop or one specific loop?  If it is one specific loop you could
configure the logger that it uses.

On 5/24/05, Ivan Linhares Martins <li...@gmail.com> wrote:
> Hi,
> 
> I´m using log4j version 1-3 alpha 6, working with Socket and File Appenders.
> 
> I would like to know if i can prevent repeated messages generated in a
> loop appearing in files or remote receivers only by configuring Log4j,
> i.e. not writing additional code. Is it possible?
> 
> Thanks,
> Ivan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 


-- 
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

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


RE: Messages in a Loop

Posted by Aron Bock <ar...@hotmail.com>.

>From: Ivan Linhares Martins <li...@gmail.com>
>Reply-To: Ivan Linhares Martins <li...@gmail.com>
>To: log4j-user@logging.apache.org
>Subject: Messages in a Loop
>Date: Tue, 24 May 2005 15:56:08 -0300
>
>Hi,
>
>I´m using log4j version 1-3 alpha 6, working with Socket and File 
>Appenders.
>
>I would like to know if i can prevent repeated messages generated in a
>loop appearing in files or remote receivers only by configuring Log4j,
>i.e. not writing additional code. Is it possible?
>
>Thanks,
>Ivan
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
>

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


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