org.apache.flume.clients.log4jappender
Class Log4jAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by org.apache.flume.clients.log4jappender.Log4jAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler
Direct Known Subclasses:
LoadBalancingLog4jAppender

public class Log4jAppender
extends org.apache.log4j.AppenderSkeleton

Appends Log4j Events to an external Flume client which is decribed by the Log4j configuration file. The appender takes two required parameters:

Hostname : This is the hostname of the first hop at which Flume (through an AvroSource) is listening for events.

Port : This the port on the above host where the Flume Source is listening for events.

A sample log4j properties file which appends to a source would look like:

log4j.appender.out2 = org.apache.flume.clients.log4jappender.Log4jAppender log4j.appender.out2.Port = 25430 log4j.appender.out2.Hostname = foobarflumesource.com log4j.logger.org.apache.flume.clients.log4jappender = DEBUG,out2

Note: Change the last line to the package of the class(es), that will do the appending.For example if classes from the package com.bar.foo are appending, the last line would be:

log4j.logger.com.bar.foo = DEBUG,out2


Field Summary
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
Log4jAppender()
          If this constructor is used programmatically rather than from a log4j conf you must set the port and hostname and then call activateOptions() before calling append().
Log4jAppender(String hostname, int port)
          Sets the hostname and port.
 
Method Summary
 void activateOptions()
          Activate the options set using setPort() and setHostname()
 void append(org.apache.log4j.spi.LoggingEvent event)
          Append the LoggingEvent, to send to the first Flume hop.
 void close()
          Closes underlying client.
 long getTimeout()
           
 boolean getUnsafeMode()
           
protected  void populateAvroHeaders(Map<String,String> hdrs, org.apache.avro.Schema schema, Object message)
           
 boolean requiresLayout()
           
 void setAvroReflectionEnabled(boolean avroReflectionEnabled)
           
 void setAvroSchemaUrl(String avroSchemaUrl)
           
 void setHostname(String hostname)
          Set the first flume hop hostname.
 void setPort(int port)
          Set the port on the hostname to connect to.
 void setTimeout(long timeout)
           
 void setUnsafeMode(boolean unsafeMode)
           
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
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
 

Constructor Detail

Log4jAppender

public Log4jAppender()
If this constructor is used programmatically rather than from a log4j conf you must set the port and hostname and then call activateOptions() before calling append().


Log4jAppender

public Log4jAppender(String hostname,
                     int port)
Sets the hostname and port. Even if these are passed the activateOptions() function must be called before calling append(), else append() will throw an Exception.

Parameters:
hostname - The first hop where the client should connect to.
port - The port to connect on the host.
Method Detail

append

public void append(org.apache.log4j.spi.LoggingEvent event)
            throws FlumeException
Append the LoggingEvent, to send to the first Flume hop.

Specified by:
append in class org.apache.log4j.AppenderSkeleton
Parameters:
event - The LoggingEvent to be appended to the flume.
Throws:
FlumeException - if the appender was closed, or the hostname and port were not setup, there was a timeout, or there was a connection error.

populateAvroHeaders

protected void populateAvroHeaders(Map<String,String> hdrs,
                                   org.apache.avro.Schema schema,
                                   Object message)

close

public void close()
           throws FlumeException
Closes underlying client. If append() is called after this function is called, it will throw an exception.

Throws:
FlumeException - if errors occur during close

requiresLayout

public boolean requiresLayout()

setHostname

public void setHostname(String hostname)
Set the first flume hop hostname.

Parameters:
hostname - The first hop where the client should connect to.

setPort

public void setPort(int port)
Set the port on the hostname to connect to.

Parameters:
port - The port to connect on the host.

setUnsafeMode

public void setUnsafeMode(boolean unsafeMode)

getUnsafeMode

public boolean getUnsafeMode()

setTimeout

public void setTimeout(long timeout)

getTimeout

public long getTimeout()

setAvroReflectionEnabled

public void setAvroReflectionEnabled(boolean avroReflectionEnabled)

setAvroSchemaUrl

public void setAvroSchemaUrl(String avroSchemaUrl)

activateOptions

public void activateOptions()
                     throws FlumeException
Activate the options set using setPort() and setHostname()

Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler
Overrides:
activateOptions in class org.apache.log4j.AppenderSkeleton
Throws:
FlumeException - if the hostname and port combination is invalid.


Copyright © 2009-2013 Apache Software Foundation. All Rights Reserved.