The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
LoggingEventFieldResolver.java
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j.spi;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.log4j.spi.location.LocationInfo;
/**
* A singleton helper utility which accepts a field name and a LoggingEvent and returns the
* String 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.
*
* @author Scott Deboy <sdeboy@apache.org>
* @author Paul Smith <psmith@apache.org>
*
*/
public final class LoggingEventFieldResolver {
public static final List keywordList = new ArrayList();
public static final String LOGGER_FIELD = "LOGGER";
public static final String LEVEL_FIELD = "LEVEL";
public static final String CLASS_FIELD = "CLASS";
public static final String FILE_FIELD = "FILE";
public static final String LINE_FIELD = "LINE";
public static final String METHOD_FIELD = "METHOD";
public static final String MSG_FIELD = "MSG";
public static final String NDC_FIELD = "NDC";
public static final String EXCEPTION_FIELD = "EXCEPTION";
public static final String TIMESTAMP_FIELD = "TIMESTAMP";
public static final String THREAD_FIELD = "THREAD";
public static final String PROP_FIELD = "PROP.";
public static final String EMPTY_STRING = "";
private static final LoggingEventFieldResolver resolver =
new LoggingEventFieldResolver();
private LoggingEventFieldResolver() {
keywordList.add(LOGGER_FIELD);
keywordList.add(LEVEL_FIELD);
keywordList.add(CLASS_FIELD);
keywordList.add(FILE_FIELD);
keywordList.add(LINE_FIELD);
keywordList.add(METHOD_FIELD);
keywordList.add(MSG_FIELD);
keywordList.add(NDC_FIELD);
keywordList.add(EXCEPTION_FIELD);
keywordList.add(TIMESTAMP_FIELD);
keywordList.add(THREAD_FIELD);
keywordList.add(PROP_FIELD);
}
public String applyFields(String replaceText, LoggingEvent event) {
if (replaceText == null) {
return null;
}
StringTokenizer tokenizer = new StringTokenizer(replaceText);
StringBuffer result = new StringBuffer();
boolean found = false;
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (isField(token) || token.toUpperCase().startsWith(PROP_FIELD)) {
result.append(getValue(token, event).toString());
found = true;
} else {
result.append(token);
}
}
if (found) {
return result.toString();
}
return null;
}
public static LoggingEventFieldResolver getInstance() {
return resolver;
}
public boolean isField(String fieldName) {
if (fieldName != null) {
return (keywordList.contains(fieldName.toUpperCase()) || fieldName.toUpperCase().startsWith(PROP_FIELD));
}
return false;
}
public Object getValue(String fieldName, LoggingEvent event) {
String upperField = fieldName.toUpperCase();
LocationInfo info = null;
if (event.locationInformationExists()) {
info = event.getLocationInformation();
}
if (LOGGER_FIELD.equals(upperField)) {
return event.getLoggerName();
} else if (LEVEL_FIELD.equals(upperField)) {
return event.getLevel();
} else if (CLASS_FIELD.equals(upperField)) {
return ((info == null) ? EMPTY_STRING : info.getClassName());
} else if (FILE_FIELD.equals(upperField)) {
return ((info == null) ? EMPTY_STRING : info.getFileName());
} else if (LINE_FIELD.equals(upperField)) {
return ((info == null) ? EMPTY_STRING : info.getLineNumber());
} else if (METHOD_FIELD.equals(upperField)) {
return ((info == null) ? EMPTY_STRING : info.getMethodName());
} else if (MSG_FIELD.equals(upperField)) {
return event.getMessage();
} else if (NDC_FIELD.equals(upperField)) {
String ndcValue = event.getNDC();
return ((ndcValue == null) ? EMPTY_STRING : ndcValue);
} else if (EXCEPTION_FIELD.equals(upperField)) {
return (event.getThrowableStrRep() == null ? EMPTY_STRING : getExceptionMessage(event.getThrowableStrRep()));
} else if (TIMESTAMP_FIELD.equals(upperField)) {
return new Long(event.getTimeStamp());
} else if (THREAD_FIELD.equals(upperField)) {
return event.getThreadName();
} else if (upperField.startsWith(PROP_FIELD)) {
//note: need to use actual fieldname since case matters
String propValue = event.getProperty(fieldName.substring(5));
return ((propValue == null) ? EMPTY_STRING : propValue);
}
//there wasn't a match, so throw a runtime exception
throw new IllegalArgumentException("Unsupported field name: " + fieldName);
}
private String getExceptionMessage(String[] exception) {
StringBuffer buff = new StringBuffer();
for (int i=0;i<exception.length;i++) {
buff.append(exception[i]);
}
return buff.toString();
}
}