use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class ThreadContextDataInjector method copyProperties.
/**
* Copies key-value pairs from the specified property list into the specified {@code StringMap}.
*
* @param properties list of configuration properties, may be {@code null}
* @param result the {@code StringMap} object to add the key-values to. Must be non-{@code null}.
*/
public static void copyProperties(final List<Property> properties, final StringMap result) {
if (properties != null) {
for (int i = 0; i < properties.size(); i++) {
final Property prop = properties.get(i);
result.putValue(prop.getName(), prop.getValue());
}
}
}
use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class AsyncLogger method actualAsyncLog.
/**
* This method is called by the EventHandler that processes the RingBufferLogEvent in a separate thread.
* Merges the contents of the configuration map into the contextData, after replacing any variables in the property
* values with the StrSubstitutor-supplied actual values.
*
* @param event the event to log
*/
public void actualAsyncLog(final RingBufferLogEvent event) {
final List<Property> properties = privateConfig.loggerConfig.getPropertyList();
if (properties != null) {
StringMap contextData = (StringMap) event.getContextData();
if (contextData.isFrozen()) {
final StringMap temp = ContextDataFactory.createContextData();
temp.putAll(contextData);
contextData = temp;
}
for (int i = 0; i < properties.size(); i++) {
final Property prop = properties.get(i);
if (contextData.getValue(prop.getName()) != null) {
// contextMap overrides config properties
continue;
}
final String value = //
prop.isValueNeedsLookup() ? //
privateConfig.config.getStrSubstitutor().replace(event, prop.getValue()) : prop.getValue();
contextData.putValue(prop.getName(), value);
}
event.setContextData(contextData);
}
final ReliabilityStrategy strategy = privateConfig.loggerConfig.getReliabilityStrategy();
strategy.log(this, event);
}
use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class PropertiesRewritePolicy method rewrite.
/**
* Rewrite the event.
* @param source a logging event that may be returned or
* used to create a new logging event.
* @return The LogEvent after rewriting.
*/
@Override
public LogEvent rewrite(final LogEvent source) {
final Map<String, String> props = new HashMap<>(source.getContextData().toMap());
for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
final Property prop = entry.getKey();
props.put(prop.getName(), entry.getValue().booleanValue() ? config.getStrSubstitutor().replace(prop.getValue()) : prop.getValue());
}
final LogEvent result = new Log4jLogEvent.Builder(source).setContextMap(props).build();
return result;
}
use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class PropertiesRewritePolicy method toString.
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append(" {");
boolean first = true;
for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
if (!first) {
sb.append(", ");
}
final Property prop = entry.getKey();
sb.append(prop.getName()).append('=').append(prop.getValue());
first = false;
}
sb.append('}');
return sb.toString();
}
use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class JeroMqAppender method createAppender.
// The ZMQ.Socket class has other set methods that we do not cover because
// they throw unsupported operation exceptions.
@PluginFactory
public static JeroMqAppender createAppender(// @formatter:off
@Required(message = "No name provided for JeroMqAppender") @PluginAttribute("name") final String name, @PluginElement("Layout") Layout<?> layout, @PluginElement("Filter") final Filter filter, @PluginElement("Properties") final Property[] properties, // Super attributes
@PluginAttribute("ignoreExceptions") final boolean ignoreExceptions, // ZMQ attributes; defaults picked from zmq.Options.
@PluginAttribute(value = "affinity", defaultLong = 0) final long affinity, @PluginAttribute(value = "backlog", defaultLong = DEFAULT_BACKLOG) final long backlog, @PluginAttribute(value = "delayAttachOnConnect") final boolean delayAttachOnConnect, @PluginAttribute(value = "identity") final byte[] identity, @PluginAttribute(value = "ipv4Only", defaultBoolean = true) final boolean ipv4Only, @PluginAttribute(value = "linger", defaultLong = -1) final long linger, @PluginAttribute(value = "maxMsgSize", defaultLong = -1) final long maxMsgSize, @PluginAttribute(value = "rcvHwm", defaultLong = DEFAULT_RCV_HWM) final long rcvHwm, @PluginAttribute(value = "receiveBufferSize", defaultLong = 0) final long receiveBufferSize, @PluginAttribute(value = "receiveTimeOut", defaultLong = -1) final int receiveTimeOut, @PluginAttribute(value = "reconnectIVL", defaultLong = DEFAULT_IVL) final long reconnectIVL, @PluginAttribute(value = "reconnectIVLMax", defaultLong = 0) final long reconnectIVLMax, @PluginAttribute(value = "sendBufferSize", defaultLong = 0) final long sendBufferSize, @PluginAttribute(value = "sendTimeOut", defaultLong = -1) final int sendTimeOut, @PluginAttribute(value = "sndHwm", defaultLong = DEFAULT_SND_HWM) final long sndHwm, @PluginAttribute(value = "tcpKeepAlive", defaultInt = -1) final int tcpKeepAlive, @PluginAttribute(value = "tcpKeepAliveCount", defaultLong = -1) final long tcpKeepAliveCount, @PluginAttribute(value = "tcpKeepAliveIdle", defaultLong = -1) final long tcpKeepAliveIdle, @PluginAttribute(value = "tcpKeepAliveInterval", defaultLong = -1) final long tcpKeepAliveInterval, @PluginAttribute(value = "xpubVerbose") final boolean xpubVerbose) // @formatter:on
{
if (layout == null) {
layout = PatternLayout.createDefaultLayout();
}
List<String> endpoints;
if (properties == null) {
endpoints = new ArrayList<>(0);
} else {
endpoints = new ArrayList<>(properties.length);
for (final Property property : properties) {
if ("endpoint".equalsIgnoreCase(property.getName())) {
final String value = property.getValue();
if (Strings.isNotEmpty(value)) {
endpoints.add(value);
}
}
}
}
LOGGER.debug("Creating JeroMqAppender with name={}, filter={}, layout={}, ignoreExceptions={}, endpoints={}", name, filter, layout, ignoreExceptions, endpoints);
return new JeroMqAppender(name, filter, layout, ignoreExceptions, endpoints, affinity, backlog, delayAttachOnConnect, identity, ipv4Only, linger, maxMsgSize, rcvHwm, receiveBufferSize, receiveTimeOut, reconnectIVL, reconnectIVLMax, sendBufferSize, sendTimeOut, sndHwm, tcpKeepAlive, tcpKeepAliveCount, tcpKeepAliveIdle, tcpKeepAliveInterval, xpubVerbose);
}
Aggregations