Class AmqpAppender
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
org.springframework.amqp.rabbit.logback.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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classSmall helper class to encapsulate a LoggingEvent, its MDC properties, and the number of retries.protected classHelper class to actually send LoggingEvents asynchronously. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey name for the application id (if there is one set via the appender config) in the message properties.static final StringKey name for the logger level name in the message propertiesstatic final StringKey name for the logger category name in the message propertiesstatic final StringKey name for the thread name in the message properties.Fields inherited from class ch.qos.logback.core.AppenderBase
name, started -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappend(ch.qos.logback.classic.spi.ILoggingEvent event) protected voidConfigure theRabbitConnectionFactoryBean.protected BlockingQueue<AmqpAppender.Event>Subclasses can override this method to inject a custom queue implementation.protected com.rabbitmq.client.ConnectionFactoryCreate theConnectionFactory.ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent>getHost()intgetPort()intReturn the number of events waiting to be sent.intgetUri()booleanbooleanbooleanbooleanbooleanbooleanbooleanisUseSsl()booleanReturn true (default) if TLS hostname verification is enabled.protected MessagepostProcessMessageBeforeSend(Message message, AmqpAppender.Event event) Subclasses may modify the final message before sending.protected MessagePropertiesvoidsetAbbreviation(int len) voidsetAddMdcAsHeaders(boolean addMdcAsHeaders) voidsetAddresses(String addresses) voidsetApplicationId(String applicationId) voidsetAutoDelete(boolean autoDelete) voidsetCharset(String charset) voidsetClientConnectionProperties(String clientConnectionProperties) Set additional client connection properties to be added to the rabbit connection, with the formkey:value[,key:value]....voidsetConnectionName(String connectionName) Set a name for the connection which will appear on the RabbitMQ Admin UI.voidsetContentEncoding(String contentEncoding) voidsetContentType(String contentType) voidsetDeclareExchange(boolean declareExchange) voidsetDeliveryMode(String deliveryMode) voidsetDurable(boolean durable) voidsetEncoder(ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> encoder) voidsetExchangeName(String exchangeName) voidsetExchangeType(String exchangeType) voidsetGenerateId(boolean generateId) voidvoidsetIncludeCallerData(boolean includeCallerData) If true, the caller data will be available in the target AMQP message.voidsetKeyStore(String keyStore) voidsetKeyStorePassphrase(String keyStorePassphrase) voidsetKeyStoreType(String keyStoreType) voidsetLayout(ch.qos.logback.core.Layout<ch.qos.logback.classic.spi.ILoggingEvent> layout) voidsetMaxSenderRetries(int maxSenderRetries) voidsetPassword(String password) voidvoidsetRoutingKeyPattern(String routingKeyPattern) voidsetSaslConfig(String saslConfig) Set theSaslConfig.voidsetSenderPoolSize(int senderPoolSize) voidsetSslAlgorithm(String sslAlgorithm) voidsetSslPropertiesLocation(String sslPropertiesLocation) voidsetTrustStore(String trustStore) voidsetTrustStorePassphrase(String trustStorePassphrase) voidsetTrustStoreType(String trustStoreType) protected voidvoidvoidsetUsername(String username) voidsetUseSsl(boolean ssl) voidsetVerifyHostname(boolean enable) Enable server hostname verification for TLS connections.voidsetVirtualHost(String virtualHost) voidstart()voidstop()protected voidupdateConnectionClientProperties(Map<String, Object> clientProperties) Subclasses can override this method to add properties to the connection client properties.Methods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
APPLICATION_ID
Key name for the application id (if there is one set via the appender config) in the message properties.- See Also:
-
CATEGORY_NAME
Key name for the logger category name in the message properties- See Also:
-
CATEGORY_LEVEL
Key name for the logger level name in the message properties- See Also:
-
THREAD_NAME
Key name for the thread name in the message properties.- See Also:
-
-
Constructor Details
-
AmqpAppender
public AmqpAppender()
-
-
Method Details
-
setRoutingKeyPattern
-
getUri
-
setUri
-
getHost
-
setHost
-
getPort
-
setPort
-
setAddresses
-
getAddresses
-
getVirtualHost
-
setVirtualHost
-
getUsername
-
setUsername
-
getPassword
-
setPassword
-
isUseSsl
public boolean isUseSsl() -
setUseSsl
public void setUseSsl(boolean ssl) -
setVerifyHostname
public void setVerifyHostname(boolean enable) Enable server hostname verification for TLS connections.- Parameters:
enable- false to disable.- Since:
- 2.1.6
- See Also:
-
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
-
setSslAlgorithm
-
getSslPropertiesLocation
-
setSslPropertiesLocation
-
getKeyStore
-
setKeyStore
-
getKeyStorePassphrase
-
setKeyStorePassphrase
-
getKeyStoreType
-
setKeyStoreType
-
getTrustStore
-
setTrustStore
-
getTrustStorePassphrase
-
setTrustStorePassphrase
-
getTrustStoreType
-
setTrustStoreType
-
getSaslConfig
-
setSaslConfig
Set theSaslConfig.- Parameters:
saslConfig- the saslConfig to set- Since:
- 1.7.14
- See Also:
-
getExchangeName
-
setExchangeName
-
getExchangeType
-
setExchangeType
-
getRoutingKeyPattern
-
isDeclareExchange
public boolean isDeclareExchange() -
setDeclareExchange
public void setDeclareExchange(boolean declareExchange) -
getContentType
-
setContentType
-
getContentEncoding
-
setContentEncoding
-
getApplicationId
-
setApplicationId
-
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
-
setDeliveryMode
-
isAutoDelete
public boolean isAutoDelete() -
setAutoDelete
public void setAutoDelete(boolean autoDelete) -
isGenerateId
public boolean isGenerateId() -
setGenerateId
public void setGenerateId(boolean generateId) -
getCharset
-
setCharset
-
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
Set a name for the connection which will appear on the RabbitMQ Admin UI.- Parameters:
connectionName- the connection name.- Since:
- 2.1.1
-
setClientConnectionProperties
Set additional client connection properties to be added to the rabbit connection, with the formkey: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:
startin interfacech.qos.logback.core.spi.LifeCycle- Overrides:
startin classch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
createRabbitConnectionFactory
protected com.rabbitmq.client.ConnectionFactory createRabbitConnectionFactory()Create theConnectionFactory.- Returns:
- a
ConnectionFactory.
-
configureRabbitConnectionFactory
Configure theRabbitConnectionFactoryBean. Sub-classes may override to customize the configuration of the bean.- Parameters:
factoryBean- theRabbitConnectionFactoryBean.
-
updateConnectionClientProperties
Subclasses can override this method to add properties to the connection client properties.- Parameters:
clientProperties- the client properties.- Since:
- 1.5.6
-
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:
stopin interfacech.qos.logback.core.spi.LifeCycle- Overrides:
stopin classch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
append
protected void append(ch.qos.logback.classic.spi.ILoggingEvent event) - Specified by:
appendin classch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
setUpExchangeDeclaration
protected void setUpExchangeDeclaration() -
prepareMessageProperties
-
postProcessMessageBeforeSend
Subclasses may modify the final message before sending.- Parameters:
message- The message.event- The event.- Returns:
- The modified message.
- Since:
- 1.4
-