log4j Appender-Sends the LOG4J log content to the agent's source

Source: Internet
Author: User
Tags log4j

The project uses log4j print content to transfer to flume


1, Flume end

The agent configuration for Flume is as follows:

12345678910111213141516 a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1 a1.sources.s1.type=avroa1.sources.s1.bind=vm1a1.sources.s1.port=41414 a1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100

Start the agent

1 flume-ng agent --conf conf/ --conf-fileconf/a1.conf --name a1 -Dflume.root.logger=INFO,console

2. Java Client

Log4j.properties

12345 log4j.rootLogger=INFO,flumelog4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppenderlog4j.appender.flume.Hostname = 192.168.1.111log4j.appender.flume.Port = 41414log4j.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,flumelog4j.appender.flume = org.apache.flume.clients.log4jappender.LoadBalancingLog4jAppenderlog4j.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

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.