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 Classes Modifier and Type Class Description protected static class
AmqpAppender.Event
Small 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.
-
Field Summary
Fields Modifier and Type Field Description static String
APPLICATION_ID
Key name for the application id (if there is one set via the appender config) in the message properties.static String
CATEGORY_LEVEL
Key name for the logger level name in the message propertiesstatic String
CATEGORY_NAME
Key name for the logger category name in the message propertiesstatic String
THREAD_NAME
Key name for the thread name in the message properties.
-
Constructor Summary
Constructors Constructor Description AmqpAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
append(ch.qos.logback.classic.spi.ILoggingEvent event)
protected void
configureRabbitConnectionFactory(RabbitConnectionFactoryBean factoryBean)
Configure theRabbitConnectionFactoryBean
.protected BlockingQueue<AmqpAppender.Event>
createEventQueue()
Subclasses can override this method to inject a custom queue implementation.protected com.rabbitmq.client.ConnectionFactory
createRabbitConnectionFactory()
Create theConnectionFactory
.String
getAddresses()
String
getApplicationId()
String
getCharset()
String
getContentEncoding()
String
getContentType()
String
getDeliveryMode()
ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent>
getEncoder()
String
getExchangeName()
String
getExchangeType()
String
getHost()
String
getKeyStore()
String
getKeyStorePassphrase()
String
getKeyStoreType()
int
getMaxSenderRetries()
String
getPassword()
Integer
getPort()
int
getQueuedEventCount()
Return the number of events waiting to be sent.String
getRoutingKeyPattern()
String
getSaslConfig()
int
getSenderPoolSize()
String
getSslAlgorithm()
String
getSslPropertiesLocation()
String
getTrustStore()
String
getTrustStorePassphrase()
String
getTrustStoreType()
URI
getUri()
String
getUsername()
String
getVirtualHost()
boolean
isAddMdcAsHeaders()
boolean
isAutoDelete()
boolean
isDeclareExchange()
boolean
isDurable()
boolean
isGenerateId()
boolean
isIncludeCallerData()
boolean
isUseSsl()
boolean
isVerifyHostname()
Return true (default) if TLS hostname verification is enabled.protected Message
postProcessMessageBeforeSend(Message message, AmqpAppender.Event event)
Subclasses may modify the final message before sending.protected MessageProperties
prepareMessageProperties(AmqpAppender.Event event)
void
setAbbreviation(int len)
void
setAddMdcAsHeaders(boolean addMdcAsHeaders)
void
setAddresses(String addresses)
void
setApplicationId(String applicationId)
void
setAutoDelete(boolean autoDelete)
void
setCharset(String charset)
void
setClientConnectionProperties(String clientConnectionProperties)
Set additional client connection properties to be added to the rabbit connection, with the formkey:value[,key:value]...
.void
setConnectionName(String connectionName)
Set a name for the connection which will appear on the RabbitMQ Admin UI.void
setContentEncoding(String contentEncoding)
void
setContentType(String contentType)
void
setDeclareExchange(boolean declareExchange)
void
setDeliveryMode(String deliveryMode)
void
setDurable(boolean durable)
void
setEncoder(ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> encoder)
void
setExchangeName(String exchangeName)
void
setExchangeType(String exchangeType)
void
setGenerateId(boolean generateId)
void
setHost(String host)
void
setIncludeCallerData(boolean includeCallerData)
If true, the caller data will be available in the target AMQP message.void
setKeyStore(String keyStore)
void
setKeyStorePassphrase(String keyStorePassphrase)
void
setKeyStoreType(String keyStoreType)
void
setLayout(ch.qos.logback.core.Layout<ch.qos.logback.classic.spi.ILoggingEvent> layout)
void
setMaxSenderRetries(int maxSenderRetries)
void
setPassword(String password)
void
setPort(Integer port)
void
setRoutingKeyPattern(String routingKeyPattern)
void
setSaslConfig(String saslConfig)
Set theSaslConfig
.void
setSenderPoolSize(int senderPoolSize)
void
setSslAlgorithm(String sslAlgorithm)
void
setSslPropertiesLocation(String sslPropertiesLocation)
void
setTrustStore(String trustStore)
void
setTrustStorePassphrase(String trustStorePassphrase)
void
setTrustStoreType(String trustStoreType)
protected void
setUpExchangeDeclaration()
void
setUri(URI uri)
void
setUsername(String username)
void
setUseSsl(boolean ssl)
void
setVerifyHostname(boolean enable)
Enable server hostname verification for TLS connections.void
setVirtualHost(String virtualHost)
void
start()
void
stop()
protected void
updateConnectionClientProperties(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, toString
-
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
-
-
-
Field Detail
-
APPLICATION_ID
public static final 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 String CATEGORY_NAME
Key name for the logger category name in the message properties- See Also:
- Constant Field Values
-
CATEGORY_LEVEL
public static final String CATEGORY_LEVEL
Key name for the logger level name in the message properties- See Also:
- Constant Field Values
-
THREAD_NAME
public static final String THREAD_NAME
Key name for the thread name in the message properties.- See Also:
- Constant Field Values
-
-
Method Detail
-
setRoutingKeyPattern
public void setRoutingKeyPattern(String routingKeyPattern)
-
getUri
public URI getUri()
-
setUri
public void setUri(URI uri)
-
getHost
public String getHost()
-
setHost
public void setHost(String host)
-
getPort
public Integer getPort()
-
setPort
public void setPort(Integer port)
-
setAddresses
public void setAddresses(String addresses)
-
getAddresses
public String getAddresses()
-
getVirtualHost
public String getVirtualHost()
-
setVirtualHost
public void setVirtualHost(String virtualHost)
-
getUsername
public String getUsername()
-
setUsername
public void setUsername(String username)
-
getPassword
public String getPassword()
-
setPassword
public void setPassword(String password)
-
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:
RabbitConnectionFactoryBean.setEnableHostnameVerification(boolean)
-
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 String getSslAlgorithm()
-
setSslAlgorithm
public void setSslAlgorithm(String sslAlgorithm)
-
getSslPropertiesLocation
public String getSslPropertiesLocation()
-
setSslPropertiesLocation
public void setSslPropertiesLocation(String sslPropertiesLocation)
-
getKeyStore
public String getKeyStore()
-
setKeyStore
public void setKeyStore(String keyStore)
-
getKeyStorePassphrase
public String getKeyStorePassphrase()
-
setKeyStorePassphrase
public void setKeyStorePassphrase(String keyStorePassphrase)
-
getKeyStoreType
public String getKeyStoreType()
-
setKeyStoreType
public void setKeyStoreType(String keyStoreType)
-
getTrustStore
public String getTrustStore()
-
setTrustStore
public void setTrustStore(String trustStore)
-
getTrustStorePassphrase
public String getTrustStorePassphrase()
-
setTrustStorePassphrase
public void setTrustStorePassphrase(String trustStorePassphrase)
-
getTrustStoreType
public String getTrustStoreType()
-
setTrustStoreType
public void setTrustStoreType(String trustStoreType)
-
getSaslConfig
public String getSaslConfig()
-
setSaslConfig
public void setSaslConfig(String saslConfig)
Set theSaslConfig
.- Parameters:
saslConfig
- the saslConfig to set- Since:
- 1.7.14
- See Also:
RabbitUtils.stringToSaslConfig(String, ConnectionFactory)
-
getExchangeName
public String getExchangeName()
-
setExchangeName
public void setExchangeName(String exchangeName)
-
getExchangeType
public String getExchangeType()
-
setExchangeType
public void setExchangeType(String exchangeType)
-
getRoutingKeyPattern
public String getRoutingKeyPattern()
-
isDeclareExchange
public boolean isDeclareExchange()
-
setDeclareExchange
public void setDeclareExchange(boolean declareExchange)
-
getContentType
public String getContentType()
-
setContentType
public void setContentType(String contentType)
-
getContentEncoding
public String getContentEncoding()
-
setContentEncoding
public void setContentEncoding(String contentEncoding)
-
getApplicationId
public String getApplicationId()
-
setApplicationId
public void setApplicationId(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 String getDeliveryMode()
-
setDeliveryMode
public void setDeliveryMode(String deliveryMode)
-
isAutoDelete
public boolean isAutoDelete()
-
setAutoDelete
public void setAutoDelete(boolean autoDelete)
-
isGenerateId
public boolean isGenerateId()
-
setGenerateId
public void setGenerateId(boolean generateId)
-
getCharset
public String getCharset()
-
setCharset
public void setCharset(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(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(String clientConnectionProperties)
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:
start
in interfacech.qos.logback.core.spi.LifeCycle
- Overrides:
start
in classch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
createRabbitConnectionFactory
protected com.rabbitmq.client.ConnectionFactory createRabbitConnectionFactory()
Create theConnectionFactory
.- Returns:
- a
ConnectionFactory
.
-
configureRabbitConnectionFactory
protected void configureRabbitConnectionFactory(RabbitConnectionFactoryBean factoryBean)
Configure theRabbitConnectionFactoryBean
. Sub-classes may override to customize the configuration of the bean.- Parameters:
factoryBean
- theRabbitConnectionFactoryBean
.
-
updateConnectionClientProperties
protected void updateConnectionClientProperties(Map<String,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 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 interfacech.qos.logback.core.spi.LifeCycle
- Overrides:
stop
in classch.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 classch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
setUpExchangeDeclaration
protected void setUpExchangeDeclaration()
-
prepareMessageProperties
protected MessageProperties prepareMessageProperties(AmqpAppender.Event 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.
- Since:
- 1.4
-
-