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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to