Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the method of integrating flume with loh4j

Shulou Source: shulou.com Published: 2022-05-31 17:15:47 09月16日 Update

This article mainly explains "what is the method of loh4j integrating flume". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the method of loh4j integrating flume".

1. Configure to start flume

① flume configuration file conf/flume-conf.properties (this file is usually flume-conf.properties.default). You can copy and modify the suffix.

The configuration file is as follows:

Agent1.channels = ch2

Agent1.sources = avro-source1

Agent1.sinks = log-sink1

# define channel

Agent1.channels.ch2.type = memory # mem channel

# define source

Agent1.sources.avro-source1.channels = ch2

Agent1.sources.avro-source1.type = avro # avro source

Agent1.sources.avro-source1.bind = 0.0.0.0

Agent1.sources.avro-source1.port = 41414

# define sink

Agent1.sinks.log-sink1.channel = ch2

Agent1.sinks.log-sink1.type = logger # logger sink

Start flume

Bin/flume-ng agent-conf conf--conf-file conf/flume-conf.properties-name agent1-Dflume.root.logger=INFO,console

II. Configuration of log4j

① adds flume appender to the log4j.properties file

Log4j.rootLogger=INFO,flume # log level, info and flume

Log4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppender

Log4j.appender.flume.Hostname = 192.168.57.133 # flume address

Log4j.appender.flume.Port = 41414 # Port on which flume source listens

Log4j.appender.flume.UnsafeMode = true

Log4j.appender.flume.layout=org.apache.log4j.PatternLayout

Log4j.appender.flume.layout.ConversionPattern=%d {yyyy-MM-dd HH:mm:ss,SSS} [% t] [% c] [% p] -% m% n

III. Testing

Add flume appender dependencies in maven

Org.apache.flume.flume-ng-clientsflume-ng-log4jappender1.6.0

Write a simple test class:

Public class Log4jTest {Logger logger = LoggerFactory.getLogger (Log4jTest.class) / * Test flume * @ Title: flumeTest * @ Description: TODO * @ param * @ return void * @ throws * / @ Test public void flumeTest () throws Exception {while (true) {logger.info ("spider", System.currentTimeMillis ()) Try {Thread.sleep (1000);} catch (Exception e) {/ / TODO: handle exception e.printStackTrace ();}

By running the test class, you can see the output of flume on the console

Thank you for your reading, the above is the content of "what is the method of loh4j integrating flume". After the study of this article, I believe you have a deeper understanding of what the method of loh4j integration of flume is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Methods integration files testing configuration learning content suffixes addresses that is ideas situations console articles logs more knowledge knowledge points ports articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple OPPO Reno NVidia Xiaomi