Class AmqpAppender

  • All Implemented Interfaces:
    ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.FilterAttachable<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.LifeCycle

    public class AmqpAppender
    extends ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
    A Logback appender that publishes logging events to an AMQP Exchange.

    A fully-configured AmqpAppender, with every option set to their defaults, would look like this:

     
     <appender name="AMQP" class="org.springframework.amqp.rabbit.logback.AmqpAppender">
         <layout>
            <pattern><![CDATA[ %d %p %t [%c] - <%m>%n ]]></pattern>
         </layout>
         <!-- <abbreviation>36</abbreviation --> <!-- no category abbreviation by default -->
         <applicationId>AmqpAppenderTest</applicationId>
         <routingKeyPattern>%property{applicationId}.%c.%p</routingKeyPattern>
         <generateId>true</generateId>
         <charset>UTF-8</charset>
         <durable>false</durable>
         <deliveryMode>NON_PERSISTENT</deliveryMode>
     </appender>
     
     
    Since:
    1.4
    Author:
    Artem Bilan, Gary Russell, Stephen Oakey, Dominique Villard, Nicolas Ristock, Eugene Gusev, Wayne Chu
    • 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()
    • Method Detail

      • setRoutingKeyPattern

        public void setRoutingKeyPattern​(java.lang.String routingKeyPattern)
      • getUri

        public java.net.URI getUri()
      • setUri

        public void setUri​(java.net.URI uri)
      • getHost

        public java.lang.String getHost()
      • setHost

        public void setHost​(java.lang.String host)
      • getPort

        public java.lang.Integer getPort()
      • setPort

        public void setPort​(java.lang.Integer port)
      • setAddresses

        public void setAddresses​(java.lang.String addresses)
      • getAddresses

        public java.lang.String getAddresses()
      • getVirtualHost

        public java.lang.String getVirtualHost()
      • setVirtualHost

        public void setVirtualHost​(java.lang.String virtualHost)
      • getUsername

        public java.lang.String getUsername()
      • setUsername

        public void setUsername​(java.lang.String username)
      • getPassword

        public java.lang.String getPassword()
      • setPassword

        public void setPassword​(java.lang.String password)
      • isUseSsl

        public boolean isUseSsl()
      • setUseSsl

        public void setUseSsl​(boolean ssl)
      • isVerifyHostname

        public boolean isVerifyHostname()
        Return true (default) if TLS hostname verification is enabled.
        Returns:
        true (default) if TLS hostname verification is enabled.
        Since:
        2.1.6
      • getSslAlgorithm

        public java.lang.String getSslAlgorithm()
      • setSslAlgorithm

        public void setSslAlgorithm​(java.lang.String sslAlgorithm)
      • getSslPropertiesLocation

        public java.lang.String getSslPropertiesLocation()
      • setSslPropertiesLocation

        public void setSslPropertiesLocation​(java.lang.String sslPropertiesLocation)
      • getKeyStore

        public java.lang.String getKeyStore()
      • setKeyStore

        public void setKeyStore​(java.lang.String keyStore)
      • getKeyStorePassphrase

        public java.lang.String getKeyStorePassphrase()
      • setKeyStorePassphrase

        public void setKeyStorePassphrase​(java.lang.String keyStorePassphrase)
      • getKeyStoreType

        public java.lang.String getKeyStoreType()
      • setKeyStoreType

        public void setKeyStoreType​(java.lang.String keyStoreType)
      • getTrustStore

        public java.lang.String getTrustStore()
      • setTrustStore

        public void setTrustStore​(java.lang.String trustStore)
      • getTrustStorePassphrase

        public java.lang.String getTrustStorePassphrase()
      • setTrustStorePassphrase

        public void setTrustStorePassphrase​(java.lang.String trustStorePassphrase)
      • getTrustStoreType

        public java.lang.String getTrustStoreType()
      • setTrustStoreType

        public void setTrustStoreType​(java.lang.String trustStoreType)
      • getSaslConfig

        public java.lang.String getSaslConfig()
      • getExchangeName

        public java.lang.String getExchangeName()
      • setExchangeName

        public void setExchangeName​(java.lang.String exchangeName)
      • getExchangeType

        public java.lang.String getExchangeType()
      • setExchangeType

        public void setExchangeType​(java.lang.String exchangeType)
      • getRoutingKeyPattern

        public java.lang.String getRoutingKeyPattern()
      • isDeclareExchange

        public boolean isDeclareExchange()
      • setDeclareExchange

        public void setDeclareExchange​(boolean declareExchange)
      • getContentType

        public java.lang.String getContentType()
      • setContentType

        public void setContentType​(java.lang.String contentType)
      • getContentEncoding

        public java.lang.String getContentEncoding()
      • setContentEncoding

        public void setContentEncoding​(java.lang.String contentEncoding)
      • getApplicationId

        public java.lang.String getApplicationId()
      • setApplicationId

        public void setApplicationId​(java.lang.String applicationId)
      • getSenderPoolSize

        public int getSenderPoolSize()
      • setSenderPoolSize

        public void setSenderPoolSize​(int senderPoolSize)
      • getMaxSenderRetries

        public int getMaxSenderRetries()
      • setMaxSenderRetries

        public void setMaxSenderRetries​(int maxSenderRetries)
      • isAddMdcAsHeaders

        public boolean isAddMdcAsHeaders()
      • setAddMdcAsHeaders

        public void setAddMdcAsHeaders​(boolean addMdcAsHeaders)
      • isDurable

        public boolean isDurable()
      • setDurable

        public void setDurable​(boolean durable)
      • getDeliveryMode

        public java.lang.String getDeliveryMode()
      • setDeliveryMode

        public void setDeliveryMode​(java.lang.String deliveryMode)
      • isAutoDelete

        public boolean isAutoDelete()
      • setAutoDelete

        public void setAutoDelete​(boolean autoDelete)
      • isGenerateId

        public boolean isGenerateId()
      • setGenerateId

        public void setGenerateId​(boolean generateId)
      • getCharset

        public java.lang.String getCharset()
      • setCharset

        public void setCharset​(java.lang.String charset)
      • setLayout

        public void setLayout​(ch.qos.logback.core.Layout<ch.qos.logback.classic.spi.ILoggingEvent> layout)
      • getEncoder

        public ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> getEncoder()
      • setEncoder

        public void setEncoder​(ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> encoder)
      • setAbbreviation

        public void setAbbreviation​(int len)
      • getQueuedEventCount

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

        public void setConnectionName​(java.lang.String connectionName)
        Set a name for the connection which will appear on the RabbitMQ Admin UI.
        Parameters:
        connectionName - the connection name.
        Since:
        2.1.1
      • setClientConnectionProperties

        public void setClientConnectionProperties​(java.lang.String clientConnectionProperties)
        Set additional client connection properties to be added to the rabbit connection, with the form key:value[,key:value]....
        Parameters:
        clientConnectionProperties - the properties.
        Since:
        1.5.6
      • isIncludeCallerData

        public boolean isIncludeCallerData()
      • setIncludeCallerData

        public void setIncludeCallerData​(boolean includeCallerData)
        If true, the caller data will be available in the target AMQP message. By default no caller data is sent to the RabbitMQ.
        Parameters:
        includeCallerData - include or on caller data
        Since:
        1.7.1
        See Also:
        ILoggingEvent.getCallerData()
      • start

        public void start()
        Specified by:
        start in interface ch.qos.logback.core.spi.LifeCycle
        Overrides:
        start in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
      • createRabbitConnectionFactory

        protected com.rabbitmq.client.ConnectionFactory createRabbitConnectionFactory()
        Create the ConnectionFactory.
        Returns:
        a ConnectionFactory.
      • updateConnectionClientProperties

        protected void updateConnectionClientProperties​(java.util.Map<java.lang.String,​java.lang.Object> clientProperties)
        Subclasses can override this method to add properties to the connection client properties.
        Parameters:
        clientProperties - the client properties.
        Since:
        1.5.6
      • createEventQueue

        protected java.util.concurrent.BlockingQueue<AmqpAppender.Event> createEventQueue()
        Subclasses can override this method to inject a custom queue implementation.
        Returns:
        the queue to use for queueing logging events before processing them.
        Since:
        2.0.1
      • stop

        public void stop()
        Specified by:
        stop in interface ch.qos.logback.core.spi.LifeCycle
        Overrides:
        stop in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
      • append

        protected void append​(ch.qos.logback.classic.spi.ILoggingEvent event)
        Specified by:
        append in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
      • setUpExchangeDeclaration

        protected void setUpExchangeDeclaration()
      • 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.
        Since:
        1.4