Log4J Appender
Appends Log4j events to a flume agent’s avro source. A client using thisappender must have the flume-ng-sdk in the classpath (eg,flume-ng-sdk-1.9.0.jar).Required properties are in bold.
Property Name | Default | Description |
---|---|---|
Hostname | – | The hostname on which a remote Flume agent is running with anavro source. |
Port | – | The port at which the remote Flume agent’s avro source islistening. |
UnsafeMode | false | If true, the appender will not throw exceptions on failure tosend the events. |
AvroReflectionEnabled | false | Use Avro Reflection to serialize Log4j events. (Do not use when users log strings) |
AvroSchemaUrl | – | A URL from which the Avro schema can be retrieved. |
Sample log4j.properties file:
- #...
- log4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppender
- log4j.appender.flume.Hostname = example.com
- log4j.appender.flume.Port = 41414
- log4j.appender.flume.UnsafeMode = true
- # configure a class's logger to output to the flume appender
- log4j.logger.org.example.MyClass = DEBUG,flume
- #...
By default each event is converted to a string by calling toString(),or by using the Log4j layout, if specified.
If the event is an instance oforg.apache.avro.generic.GenericRecord, org.apache.avro.specific.SpecificRecord,or if the property AvroReflectionEnabled is set to true then the event will beserialized using Avro serialization.
Serializing every event with its Avro schema is inefficient, so it is good practice toprovide a schema URL from which the schema can be retrieved by the downstream sink,typically the HDFS sink. If AvroSchemaUrl is not specified,then the schema will be included as a Flume header.
Sample log4j.properties file configured to use Avro serialization:
- #...
- log4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppender
- log4j.appender.flume.Hostname = example.com
- log4j.appender.flume.Port = 41414
- log4j.appender.flume.AvroReflectionEnabled = true
- log4j.appender.flume.AvroSchemaUrl = hdfs://namenode/path/to/schema.avsc
- # configure a class's logger to output to the flume appender
- log4j.logger.org.example.MyClass = DEBUG,flume
- #...