Search in sources :

Example 1 with ReliabilityStrategy

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

the class Logger method logMessage.

@Override
public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) {
    final Message msg = message == null ? new SimpleMessage(Strings.EMPTY) : message;
    final ReliabilityStrategy strategy = privateConfig.loggerConfig.getReliabilityStrategy();
    strategy.log(this, getName(), fqcn, marker, level, msg, t);
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) ReliabilityStrategy(org.apache.logging.log4j.core.config.ReliabilityStrategy)

Example 2 with ReliabilityStrategy

use of org.apache.logging.log4j.core.config.ReliabilityStrategy 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);
}
Also used : StringMap(org.apache.logging.log4j.util.StringMap) Property(org.apache.logging.log4j.core.config.Property) ReliabilityStrategy(org.apache.logging.log4j.core.config.ReliabilityStrategy)

Example 3 with ReliabilityStrategy

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

the class AsyncLogger method logMessageInCurrentThread.

/**
     * LOG4J2-471: prevent deadlock when RingBuffer is full and object being logged calls Logger.log() from its
     * toString() method
     *
     * @param fqcn fully qualified caller name
     * @param level log level
     * @param marker optional marker
     * @param message log message
     * @param thrown optional exception
     */
void logMessageInCurrentThread(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable thrown) {
    // bypass RingBuffer and invoke Appender directly
    final ReliabilityStrategy strategy = privateConfig.loggerConfig.getReliabilityStrategy();
    strategy.log(this, getName(), fqcn, marker, level, message, thrown);
}
Also used : ReliabilityStrategy(org.apache.logging.log4j.core.config.ReliabilityStrategy)

Aggregations

ReliabilityStrategy (org.apache.logging.log4j.core.config.ReliabilityStrategy)3 Property (org.apache.logging.log4j.core.config.Property)1 Message (org.apache.logging.log4j.message.Message)1 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)1 StringMap (org.apache.logging.log4j.util.StringMap)1