com.netflix.blitz4j
Class AsyncAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by com.netflix.blitz4j.AsyncAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.AppenderAttachable, org.apache.log4j.spi.OptionHandler

public class AsyncAppender
extends org.apache.log4j.AppenderSkeleton
implements org.apache.log4j.spi.AppenderAttachable

A log4j appender implementation that logs the events asynchronously after storing the events in a buffer. The buffer implementation uses an instance of MessageBatcher.

Incoming events are first stored in a queue and then worker thread(s) takes the messages and writes it to the underlying appenders. This makes the logging of the messages efficient for the following reasons 1) Logging threads do not block until the event is written to the destination, but block only until the message is written to the queue which should be way faster than having to wait until it is written to the underlying destination 2) During log storms, the in-memory buffer overflows the message to another structure which logs just the summary and not each log message

By default the buffer holds up to 10K messages and summary up to 5K entries. Depending on the memory constraints and logging frequency, both these are configurable. The summary also starts dropping its entries when it stays there longer than 1 min which is configurable as well.


Field Summary
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
AsyncAppender()
           
 
Method Summary
 void addAppender(org.apache.log4j.Appender newAppender)
           
 void append(org.apache.log4j.spi.LoggingEvent event)
           
 void close()
           
 boolean equals(java.lang.Object obj)
           
 java.util.Enumeration getAllAppenders()
           
 org.apache.log4j.Appender getAppender(java.lang.String name)
           
 int getDiscadMapSize()
           
 int hashCode()
           
 boolean isAttached(org.apache.log4j.Appender appender)
           
 void removeAllAppenders()
           
 void removeAppender(org.apache.log4j.Appender appender)
           
 void removeAppender(java.lang.String name)
           
 boolean requiresLayout()
           
 void setOriginalAppenderName(java.lang.String name)
          Sets the name of the underlying appender that is wrapped by this AsyncAppender
 
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, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncAppender

public AsyncAppender()
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

append

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

setOriginalAppenderName

public void setOriginalAppenderName(java.lang.String name)
Sets the name of the underlying appender that is wrapped by this AsyncAppender

Parameters:
name - - The name of the underlying appender

close

public void close()
Specified by:
close in interface org.apache.log4j.Appender

getAllAppenders

public java.util.Enumeration getAllAppenders()
Specified by:
getAllAppenders in interface org.apache.log4j.spi.AppenderAttachable

getAppender

public org.apache.log4j.Appender getAppender(java.lang.String name)
Specified by:
getAppender in interface org.apache.log4j.spi.AppenderAttachable

isAttached

public boolean isAttached(org.apache.log4j.Appender appender)
Specified by:
isAttached in interface org.apache.log4j.spi.AppenderAttachable

requiresLayout

public boolean requiresLayout()
Specified by:
requiresLayout in interface org.apache.log4j.Appender

removeAllAppenders

public void removeAllAppenders()
Specified by:
removeAllAppenders in interface org.apache.log4j.spi.AppenderAttachable

removeAppender

public void removeAppender(org.apache.log4j.Appender appender)
Specified by:
removeAppender in interface org.apache.log4j.spi.AppenderAttachable

removeAppender

public void removeAppender(java.lang.String name)
Specified by:
removeAppender in interface org.apache.log4j.spi.AppenderAttachable

addAppender

public void addAppender(org.apache.log4j.Appender newAppender)
Specified by:
addAppender in interface org.apache.log4j.spi.AppenderAttachable

getDiscadMapSize

@Monitor(name="discardMapSize",
         type=GAUGE)
public int getDiscadMapSize()