use of org.apache.logging.log4j.util.PerformanceSensitive in project logging-log4j2 by apache.
the class LoggerConfig method log.
/**
* Logs an event.
*
* @param loggerName The name of the Logger.
* @param fqcn The fully qualified class name of the caller.
* @param marker A Marker or null if none is present.
* @param level The event Level.
* @param data The Message.
* @param t A Throwable or null.
*/
@PerformanceSensitive("allocation")
public void log(final String loggerName, final String fqcn, final Marker marker, final Level level, final Message data, final Throwable t) {
List<Property> props = null;
if (!propertiesRequireLookup) {
props = properties;
} else {
if (properties != null) {
props = new ArrayList<>(properties.size());
final LogEvent event = Log4jLogEvent.newBuilder().setMessage(data).setMarker(marker).setLevel(level).setLoggerName(loggerName).setLoggerFqcn(fqcn).setThrown(t).build();
for (int i = 0; i < properties.size(); i++) {
final Property prop = properties.get(i);
final String value = // since LOG4J2-1575
prop.isValueNeedsLookup() ? //
config.getStrSubstitutor().replace(event, prop.getValue()) : prop.getValue();
props.add(Property.createProperty(prop.getName(), value));
}
}
}
final LogEvent logEvent = logEventFactory.createEvent(loggerName, marker, fqcn, level, data, props, t);
try {
log(logEvent);
} finally {
// LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString())
ReusableLogEventFactory.release(logEvent);
}
}
Aggregations