public class Log4jAppender
extends org.apache.log4j.AppenderSkeleton
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
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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 |
initializeClientAddress()
Resolves local host address so it can be included in event headers.
|
protected void |
populateAvroHeaders(Map<String,String> hdrs,
org.apache.avro.Schema schema) |
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) |
public Log4jAppender()
public Log4jAppender(String hostname, int port)
hostname
- The first hop where the client should connect to.port
- The port to connect on the host.public void append(org.apache.log4j.spi.LoggingEvent event) throws FlumeException
append
in class org.apache.log4j.AppenderSkeleton
event
- The LoggingEvent to be appended to the flume.FlumeException
- if the appender was closed,
or the hostname and port were not setup, there was a timeout, or there
was a connection error.protected void populateAvroHeaders(Map<String,String> hdrs, org.apache.avro.Schema schema)
public void close() throws FlumeException
FlumeException
- if errors occur during closepublic boolean requiresLayout()
public void setHostname(String hostname)
hostname
- The first hop where the client should connect to.public void setPort(int port)
port
- The port to connect on the host.public void setUnsafeMode(boolean unsafeMode)
public boolean getUnsafeMode()
public void setTimeout(long timeout)
public long getTimeout()
public void setAvroReflectionEnabled(boolean avroReflectionEnabled)
public void setAvroSchemaUrl(String avroSchemaUrl)
public void activateOptions() throws FlumeException
activateOptions
in interface org.apache.log4j.spi.OptionHandler
activateOptions
in class org.apache.log4j.AppenderSkeleton
FlumeException
- if the hostname and
port combination is invalid.protected void initializeClientAddress() throws FlumeException
FlumeException
- if local host address can not be resolved.Copyright © 2009–2019 Apache Software Foundation. All rights reserved.