Search in sources :

Example 6 with AppenderLoggingException

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();
        }
    }
}
Also used : AppenderLoggingException(org.apache.logging.log4j.core.appender.AppenderLoggingException) AppenderLoggingException(org.apache.logging.log4j.core.appender.AppenderLoggingException)

Example 7 with AppenderLoggingException

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);
    }
}
Also used : SQLException(java.sql.SQLException) AppenderLoggingException(org.apache.logging.log4j.core.appender.AppenderLoggingException)

Example 8 with AppenderLoggingException

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);
    }
}
Also used : AppenderLoggingException(org.apache.logging.log4j.core.appender.AppenderLoggingException) AppenderLoggingException(org.apache.logging.log4j.core.appender.AppenderLoggingException)

Example 9 with AppenderLoggingException

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);
    }
}
Also used : Message(javax.jms.Message) AppenderLoggingException(org.apache.logging.log4j.core.appender.AppenderLoggingException) JMSException(javax.jms.JMSException)

Example 10 with AppenderLoggingException

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);
}
Also used : AppenderLoggingException(org.apache.logging.log4j.core.appender.AppenderLoggingException) ThreadContext(org.apache.logging.log4j.ThreadContext) Marker(org.apache.logging.log4j.Marker) ReadOnlyStringMap(org.apache.logging.log4j.util.ReadOnlyStringMap)

Aggregations

AppenderLoggingException (org.apache.logging.log4j.core.appender.AppenderLoggingException)11 Logger (org.apache.logging.log4j.Logger)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 Marker (org.apache.logging.log4j.Marker)1 ThreadContext (org.apache.logging.log4j.ThreadContext)1 NullOutputStream (org.apache.logging.log4j.core.util.NullOutputStream)1 ReadOnlyStringMap (org.apache.logging.log4j.util.ReadOnlyStringMap)1