use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class MapMessageLookup method lookup.
/**
* Looks up the value for the key using the data in the LogEvent.
* @param event The current LogEvent.
* @param key the key to be looked up, may be null
* @return The value associated with the key.
*/
@Override
public String lookup(final LogEvent event, final String key) {
final Message msg = event.getMessage();
if (msg instanceof MapMessage) {
try {
final Map<String, String> properties = ((MapMessage) msg).getData();
if (properties == null) {
return "";
}
if (key == null || key.length() == 0 || key.equals("*")) {
final StringBuilder sb = new StringBuilder("{");
boolean first = true;
for (final Map.Entry<String, String> entry : properties.entrySet()) {
if (!first) {
sb.append(", ");
}
sb.append(entry.getKey()).append("=").append(entry.getValue());
first = false;
}
sb.append("}");
return sb.toString();
}
return properties.get(key);
} catch (final Exception ex) {
LOGGER.warn(LOOKUP, "Error while getting property [{}].", key, ex);
return null;
}
}
return null;
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class Log4jLogger method log.
@Override
public void log(final Marker marker, final String fqcn, final int level, final String message, final Object[] params, Throwable throwable) {
final Level log4jLevel = getLevel(level);
final org.apache.logging.log4j.Marker log4jMarker = getMarker(marker);
if (!logger.isEnabled(log4jLevel, log4jMarker, message, params)) {
return;
}
final Message msg;
if (eventLogger && marker != null && marker.contains(EVENT_MARKER) && converter != null) {
msg = converter.convertEvent(message, params, throwable);
} else if (params == null) {
msg = new SimpleMessage(message);
} else {
msg = new ParameterizedMessage(message, params, throwable);
if (throwable != null) {
throwable = msg.getThrowable();
}
}
logger.logMessage(fqcn, log4jLevel, log4jMarker, msg, throwable);
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class AbstractLogger method entryMsg.
protected EntryMessage entryMsg(final String format, final Object... params) {
final int count = params == null ? 0 : params.length;
if (count == 0) {
if (Strings.isEmpty(format)) {
return flowMessageFactory.newEntryMessage(null);
}
return flowMessageFactory.newEntryMessage(new SimpleMessage(format));
}
if (format != null) {
return flowMessageFactory.newEntryMessage(new ParameterizedMessage(format, params));
}
final StringBuilder sb = new StringBuilder();
sb.append("params(");
for (int i = 0; i < count; i++) {
if (i > 0) {
sb.append(", ");
}
final Object parm = params[i];
sb.append(parm instanceof Message ? ((Message) parm).getFormattedMessage() : String.valueOf(parm));
}
sb.append(')');
return flowMessageFactory.newEntryMessage(new SimpleMessage(sb));
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class AbstractLogger method logMessage.
protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6) {
final Message msg = messageFactory.newMessage(message, p0, p1, p2, p3, p4, p5, p6);
logMessageSafely(fqcn, level, marker, msg, msg.getThrowable());
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class AbstractLogger method logMessage.
protected void logMessage(final String fqcn, final Level level, final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
final Message message = LambdaUtil.getMessage(msgSupplier, messageFactory);
logMessageSafely(fqcn, level, marker, message, (t == null && message != null) ? message.getThrowable() : t);
}
Aggregations