Class AmqpAppender

  • All Implemented Interfaces:
    org.apache.logging.log4j.core.Appender, org.apache.logging.log4j.core.filter.Filterable, org.apache.logging.log4j.core.impl.LocationAware, org.apache.logging.log4j.core.LifeCycle, org.apache.logging.log4j.core.LifeCycle2

    @Plugin(name="RabbitMQ",
            category="Core",
            elementType="appender",
            printObject=true)
    public class AmqpAppender
    extends org.apache.logging.log4j.core.appender.AbstractAppender
    A Log4j 2 appender that publishes logging events to an AMQP Exchange.
    Since:
    1.6
    Author:
    Gary Russell, Stephen Oakey, Artem Bilan, Dominique Villard, Nicolas Ristock, Eugene Gusev, Francesco Scipioni
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  AmqpAppender.AmqpManager
      Manager class for the appender.
      protected static class  AmqpAppender.Builder  
      protected static class  AmqpAppender.Event
      Helper class to encapsulate a LoggingEvent, its MDC properties, and the number of retries.
      protected class  AmqpAppender.EventSender
      Helper class to actually send LoggingEvents asynchronously.
      • Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle

        org.apache.logging.log4j.core.LifeCycle.State
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String APPLICATION_ID
      Key name for the application id (if there is one set via the appender config) in the message properties.
      static java.lang.String CATEGORY_LEVEL
      Key name for the logger level name in the message properties.
      static java.lang.String CATEGORY_NAME
      Key name for the logger category name in the message properties.
      static java.lang.String THREAD_NAME
      Key name for the thread name in the message properties.
      • Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle

        DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
      • Fields inherited from interface org.apache.logging.log4j.core.Appender

        ELEMENT_TYPE, EMPTY_ARRAY
    • Constructor Summary

      Constructors 
      Constructor Description
      AmqpAppender​(java.lang.String name, org.apache.logging.log4j.core.Filter filter, org.apache.logging.log4j.core.Layout<? extends java.io.Serializable> layout, boolean ignoreExceptions, org.apache.logging.log4j.core.config.Property[] properties, AmqpAppender.AmqpManager manager, java.util.concurrent.BlockingQueue<AmqpAppender.Event> eventQueue)
      Construct an instance with the provided properties.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void append​(org.apache.logging.log4j.core.LogEvent event)  
      protected void doSend​(AmqpAppender.Event event, org.apache.logging.log4j.core.LogEvent logEvent, MessageProperties amqpProps)  
      int getQueuedEventCount()
      Return the number of events waiting to be sent.
      static AmqpAppender.Builder newBuilder()
      Create a new builder.
      protected Message postProcessMessageBeforeSend​(Message message, AmqpAppender.Event event)
      Subclasses may modify the final message before sending.
      protected void sendEvent​(AmqpAppender.Event event, java.util.Map<?,​?> properties)  
      protected boolean stop​(long timeout, java.util.concurrent.TimeUnit timeUnit, boolean changeLifeCycleState)  
      • Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender

        error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toString
      • Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable

        addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, start, stop
      • Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle

        equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.apache.logging.log4j.core.LifeCycle

        getState, initialize, isStarted, isStopped, start, stop
    • Field Detail

      • APPLICATION_ID

        public static final java.lang.String APPLICATION_ID
        Key name for the application id (if there is one set via the appender config) in the message properties.
        See Also:
        Constant Field Values
      • CATEGORY_NAME

        public static final java.lang.String CATEGORY_NAME
        Key name for the logger category name in the message properties.
        See Also:
        Constant Field Values
      • CATEGORY_LEVEL

        public static final java.lang.String CATEGORY_LEVEL
        Key name for the logger level name in the message properties.
        See Also:
        Constant Field Values
      • THREAD_NAME

        public static final java.lang.String THREAD_NAME
        Key name for the thread name in the message properties.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AmqpAppender

        public AmqpAppender​(java.lang.String name,
                            org.apache.logging.log4j.core.Filter filter,
                            org.apache.logging.log4j.core.Layout<? extends java.io.Serializable> layout,
                            boolean ignoreExceptions,
                            org.apache.logging.log4j.core.config.Property[] properties,
                            AmqpAppender.AmqpManager manager,
                            java.util.concurrent.BlockingQueue<AmqpAppender.Event> eventQueue)
        Construct an instance with the provided properties.
        Parameters:
        name - the name.
        filter - the filter.
        layout - the layout.
        ignoreExceptions - true to ignore exceptions.
        manager - the manager.
        eventQueue - the event queue.
        properties - the properties.
    • Method Detail

      • newBuilder

        @PluginBuilderFactory
        public static AmqpAppender.Builder newBuilder()
        Create a new builder.
        Returns:
        the builder.
      • append

        public void append​(org.apache.logging.log4j.core.LogEvent event)
      • postProcessMessageBeforeSend

        protected Message postProcessMessageBeforeSend​(Message message,
                                                       AmqpAppender.Event event)
        Subclasses may modify the final message before sending.
        Parameters:
        message - The message.
        event - The event.
        Returns:
        The modified message.
      • sendEvent

        protected void sendEvent​(AmqpAppender.Event event,
                                 java.util.Map<?,​?> properties)
      • stop

        protected boolean stop​(long timeout,
                               java.util.concurrent.TimeUnit timeUnit,
                               boolean changeLifeCycleState)
        Overrides:
        stop in class org.apache.logging.log4j.core.filter.AbstractFilterable
      • getQueuedEventCount

        public int getQueuedEventCount()
        Return the number of events waiting to be sent.
        Returns:
        the number of events waiting to be sent.