use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class FlumeEmbeddedManager method getManager.
/**
* Returns a FlumeEmbeddedManager.
* @param name The name of the manager.
* @param agents The agents to use.
* @param properties Properties for the embedded manager.
* @param batchSize The number of events to include in a batch.
* @param dataDir The directory where the Flume FileChannel should write to.
* @return A FlumeAvroManager.
*/
public static FlumeEmbeddedManager getManager(final String name, final Agent[] agents, final Property[] properties, int batchSize, final String dataDir) {
if (batchSize <= 0) {
batchSize = 1;
}
if ((agents == null || agents.length == 0) && (properties == null || properties.length == 0)) {
throw new IllegalArgumentException("Either an Agent or properties are required");
} else if (agents != null && agents.length > 0 && properties != null && properties.length > 0) {
throw new IllegalArgumentException("Cannot configure both Agents and Properties.");
}
final StringBuilder sb = new StringBuilder();
boolean first = true;
if (agents != null && agents.length > 0) {
sb.append(name).append('[');
for (final Agent agent : agents) {
if (!first) {
sb.append('_');
}
sb.append(agent.getHost()).append('-').append(agent.getPort());
first = false;
}
sb.append(']');
} else {
String sep = Strings.EMPTY;
sb.append(name).append('-');
final StringBuilder props = new StringBuilder();
for (final Property prop : properties) {
props.append(sep);
props.append(prop.getName()).append('=').append(prop.getValue());
sep = "_";
}
sb.append(NameUtil.md5(props.toString()));
}
return getManager(sb.toString(), factory, new FactoryData(name, agents, properties, batchSize, dataDir));
}
use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class DriverManagerH2ConnectionSourceTest method testH2Properties.
@Test
public void testH2Properties() throws SQLException {
final Property[] properties = new Property[] { // @formatter:off
Property.createProperty("username", JdbcH2TestHelper.USER_NAME), Property.createProperty("password", JdbcH2TestHelper.PASSWORD) // @formatter:on
};
// @formatter:off
final DriverManagerConnectionSource source = DriverManagerConnectionSource.newBuilder().setConnectionString(JdbcH2TestHelper.CONNECTION_STRING_IN_MEMORY).setProperties(properties).build();
// @formatter:on
try (Connection conn = source.getConnection()) {
Assert.assertFalse(conn.isClosed());
}
}
use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class KafkaManager method getManager.
public static KafkaManager getManager(final LoggerContext loggerContext, final String name, final String topic, final boolean syncSend, final boolean sendTimestamp, final Property[] properties, final String key, final String retryCount) {
StringBuilder sb = new StringBuilder(name);
sb.append(" ").append(topic).append(" ").append(syncSend + "");
for (Property prop : properties) {
sb.append(" ").append(prop.getName()).append("=").append(prop.getValue());
}
return getManager(sb.toString(), factory, new FactoryData(loggerContext, topic, syncSend, sendTimestamp, properties, key, retryCount));
}
use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class HttpURLConnectionManager method send.
@Override
public void send(final Layout<?> layout, final LogEvent event) throws IOException {
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setAllowUserInteraction(false);
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setRequestMethod(method);
if (connectTimeoutMillis > 0) {
urlConnection.setConnectTimeout(connectTimeoutMillis);
}
if (readTimeoutMillis > 0) {
urlConnection.setReadTimeout(readTimeoutMillis);
}
if (layout.getContentType() != null) {
urlConnection.setRequestProperty("Content-Type", layout.getContentType());
}
for (final Property header : headers) {
urlConnection.setRequestProperty(header.getName(), header.isValueNeedsLookup() ? getConfiguration().getStrSubstitutor().replace(event, header.getValue()) : header.getValue());
}
if (sslConfiguration != null) {
((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
}
if (isHttps && !verifyHostname) {
((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
}
final byte[] msg = layout.toByteArray(event);
urlConnection.setFixedLengthStreamingMode(msg.length);
urlConnection.connect();
try (final OutputStream os = urlConnection.getOutputStream()) {
os.write(msg);
}
final byte[] buffer = new byte[1024];
try (final InputStream is = urlConnection.getInputStream()) {
while (IOUtils.EOF != is.read(buffer)) {
// empty
}
} catch (final IOException e) {
final StringBuilder errorMessage = new StringBuilder();
try (final InputStream es = urlConnection.getErrorStream()) {
errorMessage.append(urlConnection.getResponseCode());
if (urlConnection.getResponseMessage() != null) {
errorMessage.append(' ').append(urlConnection.getResponseMessage());
}
if (es != null) {
errorMessage.append(" - ");
int n;
while (IOUtils.EOF != (n = es.read(buffer))) {
errorMessage.append(new String(buffer, 0, n, CHARSET));
}
}
}
if (urlConnection.getResponseCode() > -1) {
throw new IOException(errorMessage.toString());
} else {
throw e;
}
}
}
use of org.apache.logging.log4j.core.config.Property in project logging-log4j2 by apache.
the class FlumeEmbeddedManager method createManagerName.
private static String createManagerName(final String name, final Agent[] agents, final Property[] properties) {
final StringBuilder sb = new StringBuilder();
boolean first = true;
if (agents != null && agents.length > 0) {
sb.append(name).append('[');
for (final Agent agent : agents) {
if (!first) {
sb.append('_');
}
sb.append(agent.getHost()).append('-').append(agent.getPort());
first = false;
}
sb.append(']');
} else {
String sep = Strings.EMPTY;
sb.append(name).append('-');
final StringBuilder props = new StringBuilder();
for (final Property prop : properties) {
props.append(sep);
props.append(prop.getName()).append('=').append(prop.getValue());
sep = "_";
}
sb.append(NameUtil.md5(props.toString()));
}
return sb.toString();
}
Aggregations