Spring AMQP

org.springframework.amqp.rabbit.log4j
Class AmqpAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by org.springframework.amqp.rabbit.log4j.AmqpAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public class AmqpAppender
extends org.apache.log4j.AppenderSkeleton

A Log4J appender that publishes logging events to an AMQP Exchange.

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

 
   log4j.appender.amqp=org.springframework.amqp.log4j.AmqpAppender
   #-------------------------------
   ## Connection settings
   #-------------------------------
   log4j.appender.amqp.host=localhost
   log4j.appender.amqp.port=5672
   log4j.appender.amqp.username=guest
   log4j.appender.amqp.password=guest
   log4j.appender.amqp.virtualHost=/
   #-------------------------------
   ## Exchange name and type
   #-------------------------------
   log4j.appender.amqp.exchangeName=logs
   log4j.appender.amqp.exchangeType=topic
   #-------------------------------
   ## Log4J-format pattern to use to create a routing key.
   ## The application id is available as %X{applicationId}.
   #-------------------------------
   log4j.appender.amqp.routingKeyPattern=%c.%p
   #-------------------------------
   ## Whether or not to declare this configured exchange
   #-------------------------------
   log4j.appender.amqp.declareExchange=false
   #-------------------------------
   ## Flags to use when declaring the exchange
   #-------------------------------
   log4j.appender.amqp.durable=true
   log4j.appender.amqp.autoDelete=false
   #-------------------------------
   ## Message properties
   #-------------------------------
   log4j.appender.amqp.contentType=text/plain
   log4j.appender.amqp.contentEncoding=null
   #-------------------------------
   ## Sender configuration
   #-------------------------------
   log4j.appender.amqp.senderPoolSize=2
   log4j.appender.amqp.maxSenderRetries=30
   log4j.appender.amqp.applicationId=null
   #-------------------------------
   ## Standard Log4J stuff
   #-------------------------------
   log4j.appender.amqp.layout=org.apache.log4j.PatternLayout
   log4j.appender.amqp.layout.ConversionPattern=%d %p %t [%c] - <%m>%n
 
 

Author:
Jon Brisbin

Nested Class Summary
protected  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
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 properties
static String CATEGORY_NAME
          Key name for the logger category name in the message properties
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
AmqpAppender()
           
 
Method Summary
 void append(org.apache.log4j.spi.LoggingEvent event)
           
 void close()
           
 String getApplicationId()
           
 String getContentEncoding()
           
 String getContentType()
           
 String getExchangeName()
           
 String getExchangeType()
           
 String getHost()
           
 int getMaxSenderRetries()
           
 String getPassword()
           
 int getPort()
           
 String getRoutingKeyPattern()
           
 int getSenderPoolSize()
           
 String getUsername()
           
 String getVirtualHost()
           
 boolean isAutoDelete()
           
 boolean isDeclareExchange()
           
 boolean isDurable()
           
protected  void maybeDeclareExchange()
          Maybe declare the exchange.
 boolean requiresLayout()
           
 void setApplicationId(String applicationId)
           
 void setAutoDelete(boolean autoDelete)
           
 void setContentEncoding(String contentEncoding)
           
 void setContentType(String contentType)
           
 void setDeclareExchange(boolean declareExchange)
           
 void setDurable(boolean durable)
           
 void setExchangeName(String exchangeName)
           
 void setExchangeType(String exchangeType)
           
 void setHost(String host)
           
 void setMaxSenderRetries(int maxSenderRetries)
           
 void setPassword(String password)
           
 void setPort(int port)
           
 void setRoutingKeyPattern(String routingKeyPattern)
           
 void setSenderPoolSize(int senderPoolSize)
           
 void setUsername(String username)
           
 void setVirtualHost(String virtualHost)
           
protected  void startSenders()
          Submit the required number of senders into the pool.
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
activateOptions, addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

AmqpAppender

public AmqpAppender()
Method Detail

getHost

public String getHost()

setHost

public void setHost(String host)

getPort

public int getPort()

setPort

public void setPort(int port)

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)

getExchangeName

public String getExchangeName()

setExchangeName

public void setExchangeName(String exchangeName)

getExchangeType

public String getExchangeType()

setExchangeType

public void setExchangeType(String exchangeType)

getRoutingKeyPattern

public String getRoutingKeyPattern()

setRoutingKeyPattern

public void setRoutingKeyPattern(String routingKeyPattern)

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)

isDurable

public boolean isDurable()

setDurable

public void setDurable(boolean durable)

isAutoDelete

public boolean isAutoDelete()

setAutoDelete

public void setAutoDelete(boolean autoDelete)

startSenders

protected void startSenders()
Submit the required number of senders into the pool.


maybeDeclareExchange

protected void maybeDeclareExchange()
Maybe declare the exchange.


append

public void append(org.apache.log4j.spi.LoggingEvent event)
Specified by:
append in class org.apache.log4j.AppenderSkeleton

close

public void close()

requiresLayout

public boolean requiresLayout()

Spring AMQP

Copyright © 2011. All Rights Reserved.