Package org.apache.log4j.rewrite
Class RewriteAppender
- java.lang.Object
-
- org.apache.log4j.AppenderSkeleton
-
- org.apache.log4j.rewrite.RewriteAppender
-
- All Implemented Interfaces:
Appender
,AppenderAttachable
,OptionHandler
,UnrecognizedElementHandler
public class RewriteAppender extends AppenderSkeleton implements AppenderAttachable, UnrecognizedElementHandler
This appender forwards a logging request to another appender after possibly rewriting the logging event. This appender (with the appropriate policy) replaces the MapFilter, PropertyFilter and ReflectionFilter from log4j 1.3.
-
-
Field Summary
-
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
-
-
Constructor Summary
Constructors Constructor Description RewriteAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAppender(Appender newAppender)
Add appender.protected void
append(LoggingEvent event)
Subclasses ofAppenderSkeleton
should implement this method to perform actual logging.void
close()
Close thisAsyncAppender
by interrupting the dispatcher thread which will process all pending events before exiting.Enumeration
getAllAppenders()
Get iterator over attached appenders.Appender
getAppender(String name)
Get appender by name.boolean
isAttached(Appender appender)
Determines if specified appender is attached.boolean
parseUnrecognizedElement(Element element, Properties props)
Called to inform a configured object when an unrecognized child element is encountered.void
removeAllAppenders()
Removes and closes all attached appenders.void
removeAppender(String name)
Remove appender by name.void
removeAppender(Appender appender)
Removes an appender.boolean
requiresLayout()
Configurators call this method to determine if the appender requires a layout.void
setRewritePolicy(RewritePolicy rewritePolicy)
-
Methods inherited from class org.apache.log4j.AppenderSkeleton
activateOptions, addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
-
-
-
-
Method Detail
-
append
protected void append(LoggingEvent event)
Subclasses ofAppenderSkeleton
should implement this method to perform actual logging. See alsoAppenderSkeleton.doAppend
method.- Specified by:
append
in classAppenderSkeleton
-
addAppender
public void addAppender(Appender newAppender)
Add appender.- Specified by:
addAppender
in interfaceAppenderAttachable
- Parameters:
newAppender
- appender to add, may not be null.
-
getAllAppenders
public Enumeration getAllAppenders()
Get iterator over attached appenders.- Specified by:
getAllAppenders
in interfaceAppenderAttachable
- Returns:
- iterator or null if no attached appenders.
-
getAppender
public Appender getAppender(String name)
Get appender by name.- Specified by:
getAppender
in interfaceAppenderAttachable
- Parameters:
name
- name, may not be null.- Returns:
- matching appender or null.
-
close
public void close()
Close thisAsyncAppender
by interrupting the dispatcher thread which will process all pending events before exiting.
-
isAttached
public boolean isAttached(Appender appender)
Determines if specified appender is attached.- Specified by:
isAttached
in interfaceAppenderAttachable
- Parameters:
appender
- appender.- Returns:
- true if attached.
-
requiresLayout
public boolean requiresLayout()
Configurators call this method to determine if the appender requires a layout. If this method returnstrue
, meaning that layout is required, then the configurator will configure an layout using the configuration information at its disposal. If this method returnsfalse
, meaning that a layout is not required, then layout configuration will be skipped even if there is available layout configuration information at the disposal of the configurator..In the rather exceptional case, where the appender implementation admits a layout but can also work without it, then the appender should return
true
.- Specified by:
requiresLayout
in interfaceAppender
-
removeAllAppenders
public void removeAllAppenders()
Removes and closes all attached appenders.- Specified by:
removeAllAppenders
in interfaceAppenderAttachable
-
removeAppender
public void removeAppender(Appender appender)
Removes an appender.- Specified by:
removeAppender
in interfaceAppenderAttachable
- Parameters:
appender
- appender to remove.
-
removeAppender
public void removeAppender(String name)
Remove appender by name.- Specified by:
removeAppender
in interfaceAppenderAttachable
- Parameters:
name
- name.
-
setRewritePolicy
public void setRewritePolicy(RewritePolicy rewritePolicy)
-
parseUnrecognizedElement
public boolean parseUnrecognizedElement(Element element, Properties props) throws Exception
Called to inform a configured object when an unrecognized child element is encountered.- Specified by:
parseUnrecognizedElement
in interfaceUnrecognizedElementHandler
- Parameters:
element
- element, may not be null.props
- properties in force, may be null.- Returns:
- true if configured object recognized the element
- Throws:
Exception
- throw an exception to prevent activation of the configured object.
-
-