Search in sources :

Example 16 with Property

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 final String name, @PluginElement Layout<?> layout, @PluginElement final Filter filter, @PluginElement final Property[] properties, // Super attributes
@PluginAttribute final boolean ignoreExceptions, // ZMQ attributes; defaults picked from zmq.Options.
@PluginAttribute(defaultLong = 0) final long affinity, @PluginAttribute(defaultLong = DEFAULT_BACKLOG) final long backlog, @PluginAttribute final boolean delayAttachOnConnect, @PluginAttribute final byte[] identity, @PluginAttribute(defaultBoolean = true) final boolean ipv4Only, @PluginAttribute(defaultLong = -1) final long linger, @PluginAttribute(defaultLong = -1) final long maxMsgSize, @PluginAttribute(defaultLong = DEFAULT_RCV_HWM) final long rcvHwm, @PluginAttribute(defaultLong = 0) final long receiveBufferSize, @PluginAttribute(defaultLong = -1) final int receiveTimeOut, @PluginAttribute(defaultLong = DEFAULT_IVL) final long reconnectIVL, @PluginAttribute(defaultLong = 0) final long reconnectIVLMax, @PluginAttribute(defaultLong = 0) final long sendBufferSize, @PluginAttribute(defaultLong = -1) final int sendTimeOut, @PluginAttribute(defaultLong = DEFAULT_SND_HWM) final long sndHwm, @PluginAttribute(defaultInt = -1) final int tcpKeepAlive, @PluginAttribute(defaultLong = -1) final long tcpKeepAliveCount, @PluginAttribute(defaultLong = -1) final long tcpKeepAliveIdle, @PluginAttribute(defaultLong = -1) final long tcpKeepAliveInterval, @PluginAttribute 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, Property.EMPTY_ARRAY);
}
Also used : Property(org.apache.logging.log4j.core.config.Property) PluginFactory(org.apache.logging.log4j.plugins.PluginFactory)

Example 17 with Property

use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.

the class PoolingDriverConnectionSource method setupDriver.

private void setupDriver(final String connectionString, final PoolableConnectionFactoryConfig poolableConnectionFactoryConfig) throws SQLException {
    // 
    // First, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    // 
    final Property[] properties = getProperties();
    final char[] userName = getUserName();
    final char[] password = getPassword();
    final ConnectionFactory connectionFactory;
    if (properties != null && properties.length > 0) {
        if (userName != null || password != null) {
            throw new SQLException("Either set the userName and password, or set the Properties, but not both.");
        }
        connectionFactory = new DriverManagerConnectionFactory(connectionString, toProperties(properties));
    } else {
        connectionFactory = new DriverManagerConnectionFactory(connectionString, toString(userName), toString(password));
    }
    // 
    // Next, we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    // 
    final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    if (poolableConnectionFactoryConfig != null) {
        poolableConnectionFactoryConfig.init(poolableConnectionFactory);
    }
    // 
    // Now we'll need a ObjectPool that serves as the
    // actual pool of connections.
    // 
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    // 
    @SuppressWarnings("resource") final ObjectPool<PoolableConnection> // This GenericObjectPool will be closed on shutdown
    connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
    // Set the factory's pool property to the owning pool
    poolableConnectionFactory.setPool(connectionPool);
    loadDriver(poolingDriverClassName);
    final PoolingDriver driver = getPoolingDriver();
    if (driver != null) {
        getLogger().debug("Registering DBCP pool '{}' with pooling driver {}: {}", poolName, driver, connectionPool);
        driver.registerPool(poolName, connectionPool);
    }
// 
// Now we can just use the connect string "jdbc:apache:commons:dbcp:example"
// to access our pool of Connections.
// 
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) SQLException(java.sql.SQLException) PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) PoolingDriver(org.apache.commons.dbcp2.PoolingDriver) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Property(org.apache.logging.log4j.core.config.Property) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 18 with Property

use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.

the class ThreadContextBenchmark method createMap.

// from Log4jLogEvent::createMap
static Map<String, String> createMap(final List<Property> properties) {
    final Map<String, String> contextMap = ThreadContext.getImmutableContext();
    if (properties == null || properties.isEmpty()) {
        // may be ThreadContext.EMPTY_MAP but not null
        return contextMap;
    }
    final Map<String, String> map = new HashMap<>(contextMap);
    for (final Property prop : properties) {
        if (!map.containsKey(prop.getName())) {
            map.put(prop.getName(), prop.getValue());
        }
    }
    return Collections.unmodifiableMap(map);
}
Also used : HashMap(java.util.HashMap) Property(org.apache.logging.log4j.core.config.Property)

Aggregations

Property (org.apache.logging.log4j.core.config.Property)18 HashMap (java.util.HashMap)3 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)3 StringMap (org.apache.logging.log4j.util.StringMap)3 Map (java.util.Map)2 EmbeddedAgent (org.apache.flume.agent.embedded.EmbeddedAgent)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)2 Configuration (org.apache.logging.log4j.core.config.Configuration)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)1