Flume Source-loggersink

Source: Internet
Author: User

Package org.apache.flume.sink;

Import com.google.common.base.Strings;
Import Org.apache.flume.Channel;
Import Org.apache.flume.Context;
Import org.apache.flume.Event;
Import org.apache.flume.EventDeliveryException;
Import org.apache.flume.Transaction;
Import org.apache.flume.conf.Configurable;
Import Org.apache.flume.event.EventHelper;
Import Org.slf4j.Logger;
Import Org.slf4j.LoggerFactory;

public class Loggersink extends Abstractsink implements configurable {

private static final Logger Logger = loggerfactory
. GetLogger (Loggersink.class);

Default Max bytes to dump
public static final int default_max_byte_dump = 16;

Max number of bytes to be dumped
private int maxbytestolog = Default_max_byte_dump;

public static final String Max_bytes_dump_key = "Maxbytestolog";

@Override
public void Configure (context context) {
String strmaxbytes = context.getstring (Max_bytes_dump_key);
if (! Strings.isnullorempty (strmaxbytes)) {
try {
Maxbytestolog = Integer.parseint (strmaxbytes);
} catch (NumberFormatException e) {
Logger.warn (String.Format ("Unable to convert%s to integer, using the default value (%d) for Maxbytetodump",
Strmaxbytes, Default_max_byte_dump));
Maxbytestolog = Default_max_byte_dump;
}
}
}

@Override
Public Status process () throws Eventdeliveryexception {
Status result = Status.ready;
Channel channel = Getchannel ();
Transaction Transaction = Channel.gettransaction ();
Event event = null;

try {
Transaction.begin ();
event = Channel.take ();

if (event! = null) {
if (logger.isinfoenabled ()) {
Logger.info ("event:" + eventhelper.dumpevent (event, Maxbytestolog));
}
} else {
No event found, request Back-off semantics from the sink runner
result = Status.backoff;
}
Transaction.commit ();
} catch (Exception ex) {
Transaction.rollback ();
throw new Eventdeliveryexception ("Failed to log Event:" + Event, ex);
} finally {
Transaction.close ();
}

return result;
}
}

Flume Source-loggersink

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.