use of org.apache.logging.log4j.core.appender.AppenderLoggingException in project logging-log4j2 by apache.
the class FlumeAvroManager method send.
@Override
public synchronized void send(final Event event) {
if (batchSize == 1) {
if (rpcClient == null) {
rpcClient = connect(agents, retries, connectTimeoutMillis, requestTimeoutMillis);
}
if (rpcClient != null) {
try {
rpcClient.append(event);
} catch (final Exception ex) {
rpcClient.close();
rpcClient = null;
final String msg = "Unable to write to " + getName() + " at " + agents[current].getHost() + ':' + agents[current].getPort();
LOGGER.warn(msg, ex);
throw new AppenderLoggingException("No Flume agents are available");
}
} else {
final String msg = "Unable to write to " + getName() + " at " + agents[current].getHost() + ':' + agents[current].getPort();
LOGGER.warn(msg);
throw new AppenderLoggingException("No Flume agents are available");
}
} else {
batchEvent.addEvent(event);
final int eventCount = batchEvent.getEvents().size();
if (eventCount == 1) {
nextSend = System.nanoTime() + delayNanos;
}
if (eventCount >= batchSize || System.nanoTime() >= nextSend) {
send(batchEvent);
batchEvent = new BatchEvent();
}
}
}
use of org.apache.logging.log4j.core.appender.AppenderLoggingException in project logging-log4j2 by apache.
the class JdbcDatabaseManager method connectAndStart.
@Override
protected void connectAndStart() {
try {
this.connection = this.connectionSource.getConnection();
this.connection.setAutoCommit(false);
this.statement = this.connection.prepareStatement(this.sqlStatement);
} catch (final SQLException e) {
throw new AppenderLoggingException("Cannot write logging event or flush buffer; JDBC manager cannot connect to the database.", e);
}
}
use of org.apache.logging.log4j.core.appender.AppenderLoggingException in project logging-log4j2 by apache.
the class JpaDatabaseManager method connectAndStart.
@Override
protected void connectAndStart() {
try {
this.entityManager = this.entityManagerFactory.createEntityManager();
this.transaction = this.entityManager.getTransaction();
this.transaction.begin();
} catch (final Exception e) {
throw new AppenderLoggingException("Cannot write logging event or flush buffer; manager cannot create EntityManager or transaction.", e);
}
}
use of org.apache.logging.log4j.core.appender.AppenderLoggingException in project logging-log4j2 by apache.
the class JmsAppender method append.
@Override
public void append(final LogEvent event) {
try {
final Message message = this.manager.createMessage(getLayout().toSerializable(event));
message.setJMSTimestamp(event.getTimeMillis());
this.producer.send(message);
} catch (final JMSException e) {
throw new AppenderLoggingException(e);
}
}
use of org.apache.logging.log4j.core.appender.AppenderLoggingException in project logging-log4j2 by apache.
the class NoSqlDatabaseManager method writeInternal.
@Override
protected void writeInternal(final LogEvent event) {
if (!this.isRunning() || this.connection == null || this.connection.isClosed()) {
throw new AppenderLoggingException("Cannot write logging event; NoSQL manager not connected to the database.");
}
final NoSqlObject<W> entity = this.connection.createObject();
entity.set("level", event.getLevel());
entity.set("loggerName", event.getLoggerName());
entity.set("message", event.getMessage() == null ? null : event.getMessage().getFormattedMessage());
final StackTraceElement source = event.getSource();
if (source == null) {
entity.set("source", (Object) null);
} else {
entity.set("source", this.convertStackTraceElement(source));
}
final Marker marker = event.getMarker();
if (marker == null) {
entity.set("marker", (Object) null);
} else {
entity.set("marker", buildMarkerEntity(marker));
}
entity.set("threadId", event.getThreadId());
entity.set("threadName", event.getThreadName());
entity.set("threadPriority", event.getThreadPriority());
entity.set("millis", event.getTimeMillis());
entity.set("date", new java.util.Date(event.getTimeMillis()));
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") Throwable thrown = event.getThrown();
if (thrown == null) {
entity.set("thrown", (Object) null);
} else {
final NoSqlObject<W> originalExceptionEntity = this.connection.createObject();
NoSqlObject<W> exceptionEntity = originalExceptionEntity;
exceptionEntity.set("type", thrown.getClass().getName());
exceptionEntity.set("message", thrown.getMessage());
exceptionEntity.set("stackTrace", this.convertStackTrace(thrown.getStackTrace()));
while (thrown.getCause() != null) {
thrown = thrown.getCause();
final NoSqlObject<W> causingExceptionEntity = this.connection.createObject();
causingExceptionEntity.set("type", thrown.getClass().getName());
causingExceptionEntity.set("message", thrown.getMessage());
causingExceptionEntity.set("stackTrace", this.convertStackTrace(thrown.getStackTrace()));
exceptionEntity.set("cause", causingExceptionEntity);
exceptionEntity = causingExceptionEntity;
}
entity.set("thrown", originalExceptionEntity);
}
final ReadOnlyStringMap contextMap = event.getContextData();
if (contextMap == null) {
entity.set("contextMap", (Object) null);
} else {
final NoSqlObject<W> contextMapEntity = this.connection.createObject();
contextMap.forEach(new BiConsumer<String, String>() {
@Override
public void accept(final String key, final String val) {
contextMapEntity.set(key, val);
}
});
entity.set("contextMap", contextMapEntity);
}
final ThreadContext.ContextStack contextStack = event.getContextStack();
if (contextStack == null) {
entity.set("contextStack", (Object) null);
} else {
entity.set("contextStack", contextStack.asList().toArray());
}
this.connection.insertObject(entity);
}
Aggregations