码迷,mamicode.com
首页 > 其他好文 > 详细

ELK-log4j2异步输出+logstash

时间:2019-04-23 17:20:53      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:class   打印   property   file   out   span   protoc   col   oca   

1、pom.xml配置文件

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>${log4j.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<!-- log4j2 AsyncLogger need disruptor-->
<dependency>
    <groupId>com.lmax</groupId>
    <artifactId>disruptor</artifactId>
    <version>3.4.2</version>
</dependency>

 

2、log4j2.xml配置信息

<?xml version="1.0" encoding="UTF-8" ?>

<Configuration>
    <Properties>
        <property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} -%5p ${PID:-} [%15.15t] %-30.30C{1.} : %m%n</property>
    </Properties>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${LOG_PATTERN}" />
        </Console>
        
        <RollingFile name="RollingFile" fileName="d:/logs/main.log"
            filePattern="d:/logs/$${date:yyyy-MM-dd}/xinyar-%d{MM-dd-yyyy}-%i.log.gz"
            immediateFlush="false" append="true">
            <PatternLayout pattern="${LOG_PATTERN}" />
            <!-- 每个文件大小 -->
            <!-- <SizeBasedTriggeringPolicy size="50M" /> -->
            <!-- <SizeBasedTriggeringPolicy size="50KB" /> -->
            <SizeBasedTriggeringPolicy size="20M" />
            <!-- 不设置,同一文件夹下默认最多7个文件,这里设置同一文件夹下最多50个文件 -->
            <DefaultRolloverStrategy max="50" />
        </RollingFile>
     <!-- 47.*.*.159为logstash主机外网IP,4560为logstash端口 -->
        <Socket name="logstash-tcp" host="47.*.*.159" port="4560" protocol="TCP">
            <PatternLayout pattern="${LOG_PATTERN}" />
        </Socket>
    </Appenders>
    <Loggers>
        <!-- 异步发送logstash -->
        <!-- 如果使用<asyncRoot> 或 <asyncLogger>,includeLocation="true"是必须要设置才会有类路径等一些信息打印出来 -->
        <AsyncLogger name="com.xinyartech" level="info" includeLocation="true" >
            <appender-ref ref="logstash-tcp" />
        </AsyncLogger>
     
        <Root level="INFO">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="RollingFile"/>
        </Root>    
    </Loggers>
</Configuration>

 

3、logstash配置信息--test4.conf

input {
    tcp {  
        port => 4560 
        codec => json
    }  
} 
 
output {    
    elasticsearch {
        hosts => "127.0.0.1:9200"
            index => "es-message-%{+YYYY.MM.dd}"    
    }
    stdout { codec => rubydebug }
}

 

4、启动logstash
$ ./logstash -f ../config/test4.conf &

ELK-log4j2异步输出+logstash

标签:class   打印   property   file   out   span   protoc   col   oca   

原文地址:https://www.cnblogs.com/linjiqin/p/10757261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!