Package org.apache.log4j.spi
Class LoggingEventFieldResolver
- java.lang.Object
-
- org.apache.log4j.spi.LoggingEventFieldResolver
-
public final class LoggingEventFieldResolver extends java.lang.ObjectA singleton helper utility which accepts a field name and a LoggingEvent and returns the value of that field. This class defines a grammar used in creation of an expression-based Rule. The only available method is Object getField(String fieldName, LoggingEvent event). Here is a description of the mapping of field names in the grammar to fields on the logging event. While the getField method returns an Object, the individual types returned per field are described here: Field Name Field value (String representation Return type LOGGER category name (logger) String LEVEL level Level CLASS locationInformation's class name String FILE locationInformation's file name String LINE locationInformation's line number String METHOD locationInformation's method name String MSG message Object NDC NDC String EXCEPTION throwable string representation ThrowableInformation TIMESTAMP timestamp Long THREAD thread String PROP.keyName entry in the Property hashtable String mapped to the key [keyName] NOTE: the values for the 'keyName' portion of the MDC and PROP mappings must be an exact match to the key in the hashTable (case sensitive). If the passed-in field is null or doesn't match an entry in the above-described mapping, an exception is thrown.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLASS_FIELDCLASS string literal.static java.lang.StringEMPTY_STRINGempty string literal.static java.lang.StringEXCEPTION_FIELDEXCEPTION string literal.static java.lang.StringFILE_FIELDFILE string literal.static java.util.ListKEYWORD_LISTKeyword list.static java.lang.StringLEVEL_FIELDLEVEL string literal.static java.lang.StringLINE_FIELDLINE string literal.static java.lang.StringLOGGER_FIELDLOGGER string literal.static java.lang.StringMETHOD_FIELDMETHOD string literal.static java.lang.StringMSG_FIELDMSG string literal.static java.lang.StringNDC_FIELDNDC string literal.static java.lang.StringPROP_FIELDPROP.private static LoggingEventFieldResolverRESOLVERLOGGER string literal.static java.lang.StringTHREAD_FIELDTHREAD string literal.static java.lang.StringTIMESTAMP_FIELDTIMESTAMP string literal.
-
Constructor Summary
Constructors Modifier Constructor Description privateLoggingEventFieldResolver()Create new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringapplyFields(java.lang.String replaceText, org.apache.log4j.spi.LoggingEvent event)Apply fields.private static java.lang.StringgetExceptionMessage(java.lang.String[] exception)Get message from throwable representation.static LoggingEventFieldResolvergetInstance()Get singleton instance.java.lang.ObjectgetValue(java.lang.String fieldName, org.apache.log4j.spi.LoggingEvent event)Get value of field.booleanisField(java.lang.String fieldName)Determines if specified string is a recognized field.
-
-
-
Field Detail
-
KEYWORD_LIST
public static final java.util.List KEYWORD_LIST
Keyword list.
-
LOGGER_FIELD
public static final java.lang.String LOGGER_FIELD
LOGGER string literal.- See Also:
- Constant Field Values
-
LEVEL_FIELD
public static final java.lang.String LEVEL_FIELD
LEVEL string literal.- See Also:
- Constant Field Values
-
CLASS_FIELD
public static final java.lang.String CLASS_FIELD
CLASS string literal.- See Also:
- Constant Field Values
-
FILE_FIELD
public static final java.lang.String FILE_FIELD
FILE string literal.- See Also:
- Constant Field Values
-
LINE_FIELD
public static final java.lang.String LINE_FIELD
LINE string literal.- See Also:
- Constant Field Values
-
METHOD_FIELD
public static final java.lang.String METHOD_FIELD
METHOD string literal.- See Also:
- Constant Field Values
-
MSG_FIELD
public static final java.lang.String MSG_FIELD
MSG string literal.- See Also:
- Constant Field Values
-
NDC_FIELD
public static final java.lang.String NDC_FIELD
NDC string literal.- See Also:
- Constant Field Values
-
EXCEPTION_FIELD
public static final java.lang.String EXCEPTION_FIELD
EXCEPTION string literal.- See Also:
- Constant Field Values
-
TIMESTAMP_FIELD
public static final java.lang.String TIMESTAMP_FIELD
TIMESTAMP string literal.- See Also:
- Constant Field Values
-
THREAD_FIELD
public static final java.lang.String THREAD_FIELD
THREAD string literal.- See Also:
- Constant Field Values
-
PROP_FIELD
public static final java.lang.String PROP_FIELD
PROP. string literal.- See Also:
- Constant Field Values
-
EMPTY_STRING
public static final java.lang.String EMPTY_STRING
empty string literal.- See Also:
- Constant Field Values
-
RESOLVER
private static final LoggingEventFieldResolver RESOLVER
LOGGER string literal.
-
-
Method Detail
-
applyFields
public java.lang.String applyFields(java.lang.String replaceText, org.apache.log4j.spi.LoggingEvent event)Apply fields.- Parameters:
replaceText- replacement text.event- logging event.- Returns:
- evaluted expression
-
getInstance
public static LoggingEventFieldResolver getInstance()
Get singleton instance.- Returns:
- singleton instance
-
isField
public boolean isField(java.lang.String fieldName)
Determines if specified string is a recognized field.- Parameters:
fieldName- field name- Returns:
- true if recognized field.
-
getValue
public java.lang.Object getValue(java.lang.String fieldName, org.apache.log4j.spi.LoggingEvent event)Get value of field.- Parameters:
fieldName- fieldevent- event- Returns:
- value of field
-
getExceptionMessage
private static java.lang.String getExceptionMessage(java.lang.String[] exception)
Get message from throwable representation.- Parameters:
exception- exception- Returns:
- message
-
-