The project uses log4j print content to transfer to flume
1, Flume end
The agent configuration for Flume is as follows:
12345678910111213141516 |
a1.sources=s1 a1.sinks=k1 a1.channels=c1 a1.sources.s1.channels=c1 a1.sinks.k1.channel=c1 a1.sources.s1.type=avro a1.sources.s1.bind=vm1 a1.sources.s1.port=41414 a1.sinks.k1.type=logger a1.channels.c1.type=memory a1.channels.c1.capacity=1000 a1.channels.c1.transactionCapacity=100 |
Start the agent
1 |
flume-ng agent --conf conf/ --conf- file conf /a1 .conf --name a1 -Dflume.root.logger=INFO,console |
2. Java Client
Log4j.properties
12345 |
log4j.rootLogger=INFO,flume log4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppender log4j.appender.flume.Hostname = 192.168.1.111 log4j.appender.flume.Port = 41414 log4j.appender.flume.UnsafeMode = true |
The Java test code is as follows:
1234567891011121314 |
package com.test.flume;
import org.apache.log4j.Logger;
public class Log4jAppenderTest {
public static void main(String[] args) {
Logger logger = Logger.getLogger(Log4jAppenderTest.
class
);
logger.info(
"test successful"
);
logger.error(
"error"
);
System.out.println(
"ok"
);
}
}
|
Add:
1, load-balanced log4j Appender
To modify the configuration of the log4j:
123 |
log4j.rootLogger=INFO,flume log4j.appender.flume = org.apache.flume.clients.log4jappender.LoadBalancingLog4jAppender log4j.appender.flume.Hosts = 192.168.1.111:41414 192.168.1.111:41414 |
Different hosts are separated by spaces
2, log4j Appender can also use layout, as follows:
123456789101112 |
log4j.rootlogger=info, Console,flume log4j.appender.flume = Org.apache.flume.clients.log4jappender.Log4jAppender Log4j.appender.flume.Hostname = 192.168.1.111 log4j.appender.flume.port = 41414 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} [%c]-[%p]%m%n log4j.appender.console=org.apache.log4j.consoleappender Log4j.appender.console.layout=org.apache.log4j.patternlayout Log4j.appender.console.layout.conversionpattern=%-d{yyyy-mm-dd hh:mm:ss,sss} [%c]-[%p]%m%n |
From for notes (Wiz)
log4j Appender-Sends the LOG4J log content to the agent's source