Class LogFileXMLReceiver
- java.lang.Object
-
- org.apache.log4j.spi.ComponentBase
-
- org.apache.log4j.plugins.PluginSkeleton
-
- org.apache.log4j.plugins.Receiver
-
- org.apache.log4j.xml.LogFileXMLReceiver
-
- All Implemented Interfaces:
Plugin
,Component
,org.apache.log4j.spi.OptionHandler
,Thresholdable
public class LogFileXMLReceiver extends Receiver
LogFileXMLReceiver will read an xml-formated log file and make the events in the log file available to the log4j framework.This receiver supports log files created using log4j's XMLLayout, as well as java.util.logging XMLFormatter (via the org.apache.log4j.spi.Decoder interface).
By default, log4j's XMLLayout is supported (no need to specify a decoder in that case).
To configure this receiver to support java.util.logging's XMLFormatter, specify a 'decoder' param of org.apache.log4j.xml.UtilLoggingXMLDecoder.
Tailing -may- work, but not in all cases (try using a file:// URL). If a process has a log file open, the receiver may be able to read and tail the file. If the process closes the file and reopens the file, the receiver may not be able to continue tailing the file.
An expressionFilter may be specified. Only events passing the expression will be forwarded to the log4j framework.
Once the event has been "posted", it will be handled by the appenders currently configured in the LoggerRespository.
- Since:
- 1.3
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
decoder
private Decoder
decoderInstance
private org.apache.log4j.rule.Rule
expressionRule
private static java.lang.String
FILE_KEY
private java.lang.String
fileURL
private java.lang.String
filterExpression
private java.lang.String
host
private java.lang.String
path
private java.io.Reader
reader
private boolean
tailing
private boolean
useCurrentThread
-
Fields inherited from class org.apache.log4j.plugins.Receiver
thresholdLevel
-
Fields inherited from class org.apache.log4j.plugins.PluginSkeleton
active, name
-
Fields inherited from class org.apache.log4j.spi.ComponentBase
repository
-
-
Constructor Summary
Constructors Constructor Description LogFileXMLReceiver()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateOptions()
Process the filejava.lang.String
getDecoder()
Accessorjava.lang.String
getFileURL()
Accessorjava.lang.String
getFilterExpression()
Accessorboolean
isTailing()
Accessorboolean
isUseCurrentThread()
When true, this property uses the current Thread to perform the import, otherwise when false (the default), a new Thread is created and started to manage the import.static void
main(java.lang.String[] args)
private boolean
passesExpression(org.apache.log4j.spi.LoggingEvent event)
private void
process(java.io.Reader unbufferedReader)
private void
processEvents(java.util.Collection<org.apache.log4j.spi.LoggingEvent> c)
void
setDecoder(java.lang.String _decoder)
Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file.void
setFileURL(java.lang.String fileURL)
Specify the URL of the XML-formatted file to process.void
setFilterExpression(java.lang.String filterExpression)
Set the filter expression that will cause only events which pass the filter to be forwarded to the log4j framework.void
setTailing(boolean tailing)
Set the 'tailing' flag - may only work on file:// URLs and may stop tailing if the writing process closes the file and reopens.void
setUseCurrentThread(boolean useCurrentThread)
Sets whether the current Thread or a new Thread is created to perform the import, the default being false (new Thread created).void
shutdown()
Close the receiver, release any resources that are accessing the file.-
Methods inherited from class org.apache.log4j.plugins.Receiver
doPost, getThreshold, isAsSevereAsThreshold, setThreshold
-
Methods inherited from class org.apache.log4j.plugins.PluginSkeleton
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, isActive, isEquivalent, removePropertyChangeListener, removePropertyChangeListener, setLoggerRepository, setName
-
Methods inherited from class org.apache.log4j.spi.ComponentBase
getLogger, getNonFloodingLogger, resetErrorCount
-
-
-
-
Field Detail
-
fileURL
private java.lang.String fileURL
-
expressionRule
private org.apache.log4j.rule.Rule expressionRule
-
filterExpression
private java.lang.String filterExpression
-
decoder
private java.lang.String decoder
-
tailing
private boolean tailing
-
decoderInstance
private Decoder decoderInstance
-
reader
private java.io.Reader reader
-
FILE_KEY
private static final java.lang.String FILE_KEY
- See Also:
- Constant Field Values
-
host
private java.lang.String host
-
path
private java.lang.String path
-
useCurrentThread
private boolean useCurrentThread
-
-
Method Detail
-
getFileURL
public java.lang.String getFileURL()
Accessor- Returns:
- file URL
-
setFileURL
public void setFileURL(java.lang.String fileURL)
Specify the URL of the XML-formatted file to process.- Parameters:
fileURL
-
-
getDecoder
public java.lang.String getDecoder()
Accessor- Returns:
-
setDecoder
public void setDecoder(java.lang.String _decoder)
Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file.- Parameters:
_decoder
-
-
getFilterExpression
public java.lang.String getFilterExpression()
Accessor- Returns:
- filter expression
-
isTailing
public boolean isTailing()
Accessor- Returns:
- tailing flag
-
setTailing
public void setTailing(boolean tailing)
Set the 'tailing' flag - may only work on file:// URLs and may stop tailing if the writing process closes the file and reopens.- Parameters:
tailing
-
-
setFilterExpression
public void setFilterExpression(java.lang.String filterExpression)
Set the filter expression that will cause only events which pass the filter to be forwarded to the log4j framework.- Parameters:
filterExpression
-
-
passesExpression
private boolean passesExpression(org.apache.log4j.spi.LoggingEvent event)
-
main
public static void main(java.lang.String[] args)
-
shutdown
public void shutdown()
Close the receiver, release any resources that are accessing the file.
-
activateOptions
public void activateOptions()
Process the file
-
process
private void process(java.io.Reader unbufferedReader) throws java.io.IOException
- Throws:
java.io.IOException
-
processEvents
private void processEvents(java.util.Collection<org.apache.log4j.spi.LoggingEvent> c)
-
isUseCurrentThread
public final boolean isUseCurrentThread()
When true, this property uses the current Thread to perform the import, otherwise when false (the default), a new Thread is created and started to manage the import.- Returns:
-
setUseCurrentThread
public final void setUseCurrentThread(boolean useCurrentThread)
Sets whether the current Thread or a new Thread is created to perform the import, the default being false (new Thread created).- Parameters:
useCurrentThread
-
-
-