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 Sam Newman <sa...@stamplets.com> on 2001/07/25 11:47:39 UTC

Re: Multiple Appenders

My understanding is that a priority level applies to the category, not the
appenders. What about using 2 categories for the same hierarchy (I asume
root), and then attach the FileAppender to one, and the SMTPAppender to the
other?

I actually want to use 2 categories for the same classes hierarchy myself.
What I'm after is for user generated events to go to one set of appenders,
and system stuff to go to another set of appenders. Is there any problems
anyone can see with using 2 categories in this way (bearing in ind one class
could generate both user and system log entries)?

sam
----- Original Message -----
From: "Naresh Sharma" <na...@yahoo.com>
To: "log4j mailing list" <lo...@jakarta.apache.org>
Sent: Wednesday, July 25, 2001 10:43 PM
Subject: Multiple Appenders


> Hello Everybody,
>
> I have 2 appenders FileAppender and SMTPAppender now I wish that debug,
> info and warn priority messages to be sent to the file specified with
> FileAppender but Error and fatel priority message should be logged by
> SMTPAppender. Is this possible with Log4J?
>
>
> Thanks
> Naresh
>



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


Re: Multiple Appenders

Posted by Ceki Gülcü <cg...@qos.ch>.
My message was not directed only at you. If you send only text messages, then feel free to ignore my previous message. However, there are many who send HTML messages. I'd rather see plaintext messages. Regards, Ceki

At 12:35 26.07.2001 +0100, you wrote:
>err....not sure if I understand you Ceki? As far as I can see I am sending
>plain text to the list - at least thats what Outlook says....
>
>sam
>----- Original Message -----
>From: "Ceki Gülcü" <cg...@qos.ch>
>To: "LOG4J Users Mailing List" <lo...@jakarta.apache.org>
>Sent: Thursday, July 26, 2001 12:28 PM
>Subject: Re: Multiple Appenders
>
>
>>
>> Summary: Do your best to ensure that you are not sending HTML or
>"Stylelized" email to the list.
>>
>> If you are using Outlook or Outlook Express or Eudora, chances are that
>you are sending HTML email by default. There is usually a setting that will
>allow you to send "Plain Text" email. If you are using Microsoft products to
>send email, there are several bugs in the software that prevent you from
>turning off the sending of HTML email. Please read this
>http://jakarta.apache.org/site/micromail.html as well...
>>

--
Ceki Gülcü - http://qos.ch


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


Re: Multiple Appenders

Posted by Sam Newman <sa...@stamplets.com>.
err....not sure if I understand you Ceki? As far as I can see I am sending
plain text to the list - at least thats what Outlook says....

sam
----- Original Message -----
From: "Ceki Gülcü" <cg...@qos.ch>
To: "LOG4J Users Mailing List" <lo...@jakarta.apache.org>
Sent: Thursday, July 26, 2001 12:28 PM
Subject: Re: Multiple Appenders


>
> Summary: Do your best to ensure that you are not sending HTML or
"Stylelized" email to the list.
>
> If you are using Outlook or Outlook Express or Eudora, chances are that
you are sending HTML email by default. There is usually a setting that will
allow you to send "Plain Text" email. If you are using Microsoft products to
send email, there are several bugs in the software that prevent you from
turning off the sending of HTML email. Please read this
http://jakarta.apache.org/site/micromail.html as well...
>



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


Re: Multiple Appenders

Posted by Ceki Gülcü <cg...@qos.ch>.
Summary: Do your best to ensure that you are not sending HTML or "Stylelized" email to the list. 

If you are using Outlook or Outlook Express or Eudora, chances are that you are sending HTML email by default. There is usually a setting that will allow you to send "Plain Text" email. If you are using Microsoft products to send email, there are several bugs in the software that prevent you from turning off the sending of HTML email. Please read this http://jakarta.apache.org/site/micromail.html as well... 


At 09:11 26.07.2001 +0100, you wrote:
>The only way I can think of doing that would be to define 2 priority levels of your own choosing both with the same priority level - the use of prioritys with appenders explicitly says it will include all priorties and above because as far as its concerned nothing else makes any sense. I guess you could always change this your self though by overiding the use of the priortiy in your own appenders - e.g. just make your own version of the FileAppender?
> 
>sam  
>----- Original Message ----- 
>From: <ma...@emis-intl.com>randip singh 
>To: <ma...@jakarta.apache.org>'LOG4J Users Mailing List' 
>Sent: Wednesday, July 25, 2001 4:56 PM 
>Subject: RE: Multiple Appenders
>
>sam 
>
> If I dont want a "priority and above" but just one "priority" per-se , what  
>is the best mechanism ? 
>
>randi

--
Ceki Gülcü - http://qos.ch


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


Re: Multiple Appenders

Posted by Sam Newman <sa...@stamplets.com>.
RE: Multiple AppendersThe only way I can think of doing that would be to define 2 priority levels of your own choosing both with the same priority level - the use of prioritys with appenders explicitly says it will include all priorties and above because as far as its concerned nothing else makes any sense. I guess you could always change this your self though by overiding the use of the priortiy in your own appenders - e.g. just make your own version of the FileAppender?

sam
  ----- Original Message ----- 
  From: randip singh 
  To: 'LOG4J Users Mailing List' 
  Sent: Wednesday, July 25, 2001 4:56 PM
  Subject: RE: Multiple Appenders


  sam 

   If I dont want a "priority and above" but just one "priority" per-se , what 
  is the best mechanism ? 

  randi


RE: Multiple Appenders

Posted by randip singh <rs...@emis-intl.com>.
sam

 If I dont want a "priority and above" but just one "priority" per-se , what
is the best mechanism ?

randi

:+>-----Original Message-----
:+>From: Sam Newman [mailto:sam.newman@stamplets.com]
:+>Sent: Wednesday, July 25, 2001 11:09 AM
:+>To: LOG4J Users Mailing List
:+>Subject: Re: Multiple Appenders
:+>
:+>
:+>Naresh,
:+>
:+>I've just found this alternative to logging to different
:+>appenders given the
:+>priority - it comes straight from the log4j FAQ
:+>(http://jakarta.apache.org/log4j/docs/FAQ.html#filterByPriori
:+>ty to be exact)
:+>I should of checked it eariler myself!:
:+>
:+>"Setting the Threshold option of any appender extending
:+>AppenderSkeleton,
:+>(most log4j appenders extend AppenderSkeleton) to filter out
:+>all log events
:+>with lower priority than the value of the threshold option.
:+>
:+>For example, setting the threshold of an appender to DEBUG
:+>also allow INFO,
:+>WARN, ERROR and FATAL messages to log along with DEBUG
:+>messages. (DEBUG is
:+>the lowest priority). This is usually acceptable as there is
:+>little use for
:+>DEBUG messages without the surrounding INFO, WARN, ERROR and
:+>FATAL messages.
:+>Similarly, setting the threshold of an appender to ERROR
:+>will filter out
:+>DEBUG, INFO and ERROR messages but not FATAL messages.
:+>
:+>This policy usually best encapsulates what the user actually
:+>wants to do, as
:+>opposed to her mind-projected solution.
:+>
:+>See sort4.lcf for an example threshold configuration.
:+>
:+>If you must filter events by exact priority match, then you
:+>can attach a
:+>PriorityMatchFilter to any appender to filter out logging
:+>events by exact
:+>priority match."
:+>
:+>sort4.lcf:
:+>
:+># Attach appender A1 to root. Set root priority to Prority.DEBUG.
:+>log4j.rootCategory=DEBUG, A1
:+>
:+>
:+>
:+># A1 is set to be a FileAppender sending its output to
:+># System.out. However, only error messages and above will be printed
:+># since the threshold is set to Priority.ERROR.
:+>
:+># The fact that the root priority is set to Prority.DEBUG only
:+># influences log requests made to the root category. It has no
:+># influence on the appenders attached to root.
:+>
:+>log4j.appender.A1=org.apache.log4j.ConsoleAppender
:+>log4j.appender.A1.Threshold=ERROR
:+>
:+>
:+>log4j.appender.A1.layout=org.apache.log4j.PatternLayout
:+>log4j.appender.A1.layout.ConversionPattern=%p [%t] %c{2}
:+>(%M:%L) - %m%n
:+>
:+># Set the priority of the category named
:+>"org.apache.log4j.examples" to
:+># Priority.INFO, attach appender A2.
:+>log4j.category.org.apache.log4j.examples=INFO, A2
:+>
:+># Appender A2 writes to the file "test" in user's home.
:+>log4j.appender.A2=org.apache.log4j.FileAppender
:+>log4j.appender.A2.File=${user.home}/test
:+>
:+># Truncate 'test' if it aleady exists.
:+>log4j.appender.A2.Append=false
:+>
:+># Appender A2 uses the PatternLayout.
:+>log4j.appender.A2.layout=org.apache.log4j.PatternLayout
:+>log4j.appender.A2.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n
:+>
:+>
:+>HTH,
:+>sam
:+>
:+>
:+>---------------------------------------------------------------------
:+>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
:+>For additional commands, e-mail: log4j-user-help@jakarta.apache.org
:+>
:+>

Re: Multiple Appenders

Posted by Sam Newman <sa...@stamplets.com>.
Naresh,

I've just found this alternative to logging to different appenders given the
priority - it comes straight from the log4j FAQ
(http://jakarta.apache.org/log4j/docs/FAQ.html#filterByPriority to be exact)
I should of checked it eariler myself!:

"Setting the Threshold option of any appender extending AppenderSkeleton,
(most log4j appenders extend AppenderSkeleton) to filter out all log events
with lower priority than the value of the threshold option.

For example, setting the threshold of an appender to DEBUG also allow INFO,
WARN, ERROR and FATAL messages to log along with DEBUG messages. (DEBUG is
the lowest priority). This is usually acceptable as there is little use for
DEBUG messages without the surrounding INFO, WARN, ERROR and FATAL messages.
Similarly, setting the threshold of an appender to ERROR will filter out
DEBUG, INFO and ERROR messages but not FATAL messages.

This policy usually best encapsulates what the user actually wants to do, as
opposed to her mind-projected solution.

See sort4.lcf for an example threshold configuration.

If you must filter events by exact priority match, then you can attach a
PriorityMatchFilter to any appender to filter out logging events by exact
priority match."

sort4.lcf:

# Attach appender A1 to root. Set root priority to Prority.DEBUG.
log4j.rootCategory=DEBUG, A1



# A1 is set to be a FileAppender sending its output to
# System.out. However, only error messages and above will be printed
# since the threshold is set to Priority.ERROR.

# The fact that the root priority is set to Prority.DEBUG only
# influences log requests made to the root category. It has no
# influence on the appenders attached to root.

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.Threshold=ERROR


log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%p [%t] %c{2} (%M:%L) - %m%n

# Set the priority of the category named "org.apache.log4j.examples" to
# Priority.INFO, attach appender A2.
log4j.category.org.apache.log4j.examples=INFO, A2

# Appender A2 writes to the file "test" in user's home.
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=${user.home}/test

# Truncate 'test' if it aleady exists.
log4j.appender.A2.Append=false

# Appender A2 uses the PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n


HTH,
sam


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


Re: Multiple Appenders

Posted by Naresh Sharma <na...@yahoo.com>.
Hello Sam,


Thanks for the answer. Yes i think the way you suggested is good and will solve
my purpose to route different messages to different mediums.

onemore thing do you have some sample source code for this, or kind of similar.


Thanks
Naresh

Sam Newman wrote:

> My understanding is that a priority level applies to the category, not the
> appenders. What about using 2 categories for the same hierarchy (I asume
> root), and then attach the FileAppender to one, and the SMTPAppender to the
> other?
>
> I actually want to use 2 categories for the same classes hierarchy myself.
> What I'm after is for user generated events to go to one set of appenders,
> and system stuff to go to another set of appenders. Is there any problems
> anyone can see with using 2 categories in this way (bearing in ind one class
> could generate both user and system log entries)?
>
> sam
> ----- Original Message -----
> From: "Naresh Sharma" <na...@yahoo.com>
> To: "log4j mailing list" <lo...@jakarta.apache.org>
> Sent: Wednesday, July 25, 2001 10:43 PM
> Subject: Multiple Appenders
>
> > Hello Everybody,
> >
> > I have 2 appenders FileAppender and SMTPAppender now I wish that debug,
> > info and warn priority messages to be sent to the file specified with
> > FileAppender but Error and fatel priority message should be logged by
> > SMTPAppender. Is this possible with Log4J?
> >
> >
> > Thanks
> > Naresh
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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