"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-samples/log4j-samples-loggerProperties/src/main/java/org/apache/logging/log4j/lookup/MapMessageLookup.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

MapMessageLookup.java  (apache-log4j-2.11.1-src):MapMessageLookup.java  (apache-log4j-2.11.2-src)
skipping to change at line 26 skipping to change at line 26
*/ */
package org.apache.logging.log4j.lookup; package org.apache.logging.log4j.lookup;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager; import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.lookup.AbstractLookup; import org.apache.logging.log4j.core.lookup.AbstractLookup;
import org.apache.logging.log4j.core.lookup.StrLookup; import org.apache.logging.log4j.core.lookup.StrLookup;
import org.apache.logging.log4j.message.MapMessage;
import org.apache.logging.log4j.message.StringMapMessage; import org.apache.logging.log4j.message.StringMapMessage;
import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.status.StatusLogger;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
/** /**
* *
skipping to change at line 55 skipping to change at line 56
/** /**
* Looks up the value for the key using the data in the LogEvent. * Looks up the value for the key using the data in the LogEvent.
* @param event The current LogEvent. * @param event The current LogEvent.
* @param key the key to be looked up, may be null * @param key the key to be looked up, may be null
* @return The value associated with the key. * @return The value associated with the key.
*/ */
@Override @Override
public String lookup(final LogEvent event, final String key) { public String lookup(final LogEvent event, final String key) {
final Message msg = event.getMessage(); final Message msg = event.getMessage();
if (msg instanceof StringMapMessage) { if (msg instanceof MapMessage) {
try { try {
final Map<String, String> properties = ((StringMapMessage) msg). MapMessage<?, ?> mapMessage = (MapMessage) msg;
getData();
if (properties == null) {
return "";
}
if (key == null || key.length() == 0 || key.equals("*")) { if (key == null || key.length() == 0 || key.equals("*")) {
final StringBuilder sb = new StringBuilder("{"); return mapMessage.asString(MapMessage.MapFormat.JAVA_UNQUOTE
boolean first = true; D.name());
for (final Map.Entry<String, String> entry : properties.entr
ySet()) {
if (!first) {
sb.append(", ");
}
sb.append(entry.getKey()).append("=").append(entry.getVa
lue());
first = false;
}
sb.append("}");
return sb.toString();
} }
return properties.get(key); return mapMessage.get(key);
} catch (final Exception ex) { } catch (final Exception ex) {
LOGGER.warn(LOOKUP, "Error while getting property [{}].", key, e x); LOGGER.warn(LOOKUP, "Error while getting property [{}].", key, e x);
return null; return null;
} }
} }
return null; return null;
} }
public static void setLoggerProperties(final String loggerName, final Map<St ring, String> properties) { public static void setLoggerProperties(final String loggerName, final Map<St ring, String> properties) {
loggerProperties.put(loggerName, properties); loggerProperties.put(loggerName, properties);
 End of changes. 5 change blocks. 
20 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)