org.apache.log4j.varia
クラス LogFilePatternReceiver

java.lang.Object
  上位を拡張 org.apache.log4j.spi.ComponentBase
      上位を拡張 org.apache.log4j.plugins.PluginSkeleton
          上位を拡張 org.apache.log4j.plugins.Receiver
              上位を拡張 org.apache.log4j.varia.LogFilePatternReceiver
すべての実装されたインタフェース:
org.apache.log4j.plugins.Plugin, org.apache.log4j.spi.Component, org.apache.log4j.spi.OptionHandler, org.apache.log4j.spi.Thresholdable

public class LogFilePatternReceiver
extends org.apache.log4j.plugins.Receiver

LogFilePatternReceiver can parse and tail log files, converting entries into LoggingEvents. If the file doesn't exist when the receiver is initialized, the receiver will look for the file once every 10 seconds.

This receiver relies on ORO Perl5 features to perform the parsing of text in the log file, however the only regular expression field explicitly supported is a glob-style wildcard used to ignore fields in the log file if needed. All other fields are parsed by using the supplied keywords.

Features:
- specify the URL of the log file to be processed
- specify the timestamp format in the file (if one exists, using patterns from SimpleDateFormat)
- specify the pattern (logFormat) used in the log file using keywords, a wildcard character (*) and fixed text
- 'tail' the file (allows the contents of the file to be continually read and new events processed)
- supports the parsing of multi-line messages and exceptions - 'hostname' property set to URL host (or 'file' if not available) - 'application' property set to URL path (or value of fileURL if not available)

Keywords:
TIMESTAMP
LOGGER
LEVEL
THREAD
CLASS
FILE
LINE
METHOD
RELATIVETIME
MESSAGE
NDC
PROP(key)

Use a * to ignore portions of the log format that should be ignored

Example:
If your file's patternlayout is this:
%d %-5p [%t] %C{2} (%F:%L) - %m%n

specify this as the log format:
TIMESTAMP LEVEL [THREAD] CLASS (FILE:LINE) - MESSAGE

To define a PROPERTY field, use PROP(key)

Example:
If you used the RELATIVETIME pattern layout character in the file, you can use PROP(RELATIVETIME) in the logFormat definition to assign the RELATIVETIME field as a property on the event.

If your file's patternlayout is this:
%r [%t] %-5p %c %x - %m%n

specify this as the log format:
PROP(RELATIVETIME) [THREAD] LEVEL LOGGER * - MESSAGE

Note the * - it can be used to ignore a single word or sequence of words in the log file (in order for the wildcard to ignore a sequence of words, the text being ignored must be followed by some delimiter, like '-' or '[') - ndc is being ignored in the following example.

Assign a filterExpression in order to only process events which match a filter. If a filterExpression is not assigned, all events are processed.

Limitations:
- no support for the single-line version of throwable supported by patternlayout
(this version of throwable will be included as the last line of the message)
- the relativetime patternLayout character must be set as a property: PROP(RELATIVETIME)
- messages should appear as the last field of the logFormat because the variability in message content
- exceptions are converted if the exception stack trace (other than the first line of the exception)
is stored in the log file with a tab followed by the word 'at' as the first characters in the line
- tailing may fail if the file rolls over.

Example receiver configuration settings (add these as params, specifying a LogFilePatternReceiver 'plugin'):
param: "timestampFormat" value="yyyy-MM-d HH:mm:ss,SSS"
param: "logFormat" value="PROP(RELATIVETIME) [THREAD] LEVEL LOGGER * - MESSAGE"
param: "fileURL" value="file:///c:/events.log"
param: "tailing" value="true"

This configuration will be able to process these sample events:
710 [ Thread-0] DEBUG first.logger first - something here something else
880 [ Thread-2] DEBUG first.logger third - something here something else
880 [ Thread-0] INFO first.logger first - infomsg-0
java.lang.Exception: someexception-first
at Generator2.run(Generator2.java:102)

作成者:
Scott Deboy

フィールドの概要
static int MISSING_FILE_RETRY_MILLIS
           
 
クラス org.apache.log4j.plugins.Receiver から継承されたフィールド
thresholdLevel
 
クラス org.apache.log4j.plugins.PluginSkeleton から継承されたフィールド
active, name
 
クラス org.apache.log4j.spi.ComponentBase から継承されたフィールド
repository
 
コンストラクタの概要
LogFilePatternReceiver()
           
 
メソッドの概要
 void activateOptions()
          Read and process the log file.
protected  void createPattern()
          create the regular expression pattern using the input regular expression
 java.lang.String getCustomLevelDefinitions()
           
 java.lang.String getFileURL()
          Accessor
 java.lang.String getFilterExpression()
          Accessor
 java.lang.String getLogFormat()
          Accessor
 java.lang.String getPath()
           
 java.lang.String getTimestampFormat()
          Accessor
 long getWaitMillis()
          Accessor
protected  void initialize()
          Build the regular expression needed to parse log entries
 boolean isAppendNonMatches()
          Accessor
 boolean isTailing()
          Accessor
 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.
protected  void process(java.io.BufferedReader bufferedReader)
          Read, parse and optionally tail the log file, converting entries into logging events.
 void setAppendNonMatches(boolean appendNonMatches)
          Mutator
 void setCustomLevelDefinitions(java.lang.String customLevelDefinitions)
          If the log file contains non-log4j level strings, they can be mapped to log4j levels using the format (android example): V=TRACE,D=DEBUG,I=INFO,W=WARN,E=ERROR,F=FATAL,S=OFF
 void setFileURL(java.lang.String fileURL)
          Mutator
 void setFilterExpression(java.lang.String filterExpression)
          Mutator
protected  void setHost(java.lang.String host)
           
 void setLogFormat(java.lang.String logFormat)
          Mutator
protected  void setPath(java.lang.String path)
           
 void setTailing(boolean tailing)
          Mutator
 void setTimestampFormat(java.lang.String timestampFormat)
          Mutator.
 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 setWaitMillis(long waitMillis)
          Mutator
 void shutdown()
          Close the reader.
 
クラス org.apache.log4j.plugins.Receiver から継承されたメソッド
doPost, getThreshold, isAsSevereAsThreshold, setThreshold
 
クラス org.apache.log4j.plugins.PluginSkeleton から継承されたメソッド
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, isActive, isEquivalent, removePropertyChangeListener, removePropertyChangeListener, setLoggerRepository, setName
 
クラス org.apache.log4j.spi.ComponentBase から継承されたメソッド
getLogger, getNonFloodingLogger, resetErrorCount
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

MISSING_FILE_RETRY_MILLIS

public static final int MISSING_FILE_RETRY_MILLIS
関連項目:
定数フィールド値
コンストラクタの詳細

LogFilePatternReceiver

public LogFilePatternReceiver()
メソッドの詳細

getFileURL

public java.lang.String getFileURL()
Accessor

戻り値:
file URL

setFileURL

public void setFileURL(java.lang.String fileURL)
Mutator

パラメータ:
fileURL -

setCustomLevelDefinitions

public void setCustomLevelDefinitions(java.lang.String customLevelDefinitions)
If the log file contains non-log4j level strings, they can be mapped to log4j levels using the format (android example): V=TRACE,D=DEBUG,I=INFO,W=WARN,E=ERROR,F=FATAL,S=OFF

パラメータ:
customLevelDefinitions - the level definition string

getCustomLevelDefinitions

public java.lang.String getCustomLevelDefinitions()

isAppendNonMatches

public boolean isAppendNonMatches()
Accessor

戻り値:
append non matches

setAppendNonMatches

public void setAppendNonMatches(boolean appendNonMatches)
Mutator

パラメータ:
appendNonMatches -

getFilterExpression

public java.lang.String getFilterExpression()
Accessor

戻り値:
filter expression

setFilterExpression

public void setFilterExpression(java.lang.String filterExpression)
Mutator

パラメータ:
filterExpression -

isTailing

public boolean isTailing()
Accessor

戻り値:
tailing

setTailing

public void setTailing(boolean tailing)
Mutator

パラメータ:
tailing -

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.

戻り値:

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).

パラメータ:
useCurrentThread -

getLogFormat

public java.lang.String getLogFormat()
Accessor

戻り値:
log format

setLogFormat

public void setLogFormat(java.lang.String logFormat)
Mutator

パラメータ:
logFormat - the format

setTimestampFormat

public void setTimestampFormat(java.lang.String timestampFormat)
Mutator. Specify a pattern from SimpleDateFormat

パラメータ:
timestampFormat -

getTimestampFormat

public java.lang.String getTimestampFormat()
Accessor

戻り値:
timestamp format

getWaitMillis

public long getWaitMillis()
Accessor

戻り値:
millis between retrieves of content

setWaitMillis

public void setWaitMillis(long waitMillis)
Mutator

パラメータ:
waitMillis -

process

protected void process(java.io.BufferedReader bufferedReader)
                throws java.io.IOException
Read, parse and optionally tail the log file, converting entries into logging events. A runtimeException is thrown if the logFormat pattern is malformed according to ORO's Perl5Compiler.

パラメータ:
bufferedReader -
例外:
java.io.IOException

createPattern

protected void createPattern()
create the regular expression pattern using the input regular expression


setHost

protected void setHost(java.lang.String host)

setPath

protected void setPath(java.lang.String path)

getPath

public java.lang.String getPath()

initialize

protected void initialize()
Build the regular expression needed to parse log entries


shutdown

public void shutdown()
Close the reader.


activateOptions

public void activateOptions()
Read and process the log file.



Copyright © 2010 Apache Software Foundation. All Rights Reserved.