• 整合elk(2)(十三)


    配置、启动kibana

    到kibana的安装目录:

    1
    ./bin/kibana

      

    默认配置即可。

    访问localhost:5601,网页显示:

    image.png

    证明启动成功。

    创建springboot工程

    起步依赖如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
     
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-log4j</artifactId>
                <version>1.3.8.RELEASE</version>
            </dependency>
     
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
     
     
        </dependencies>

      

    log4j的配置,/src/resources/log4j.properties如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    log4j.rootLogger=INFO,console
     
    for package com.demo.elk, log would be sent to socket appender.
    log4j.logger.com.forezp=DEBUG, socket
     
    # appender socket
    log4j.appender.socket=org.apache.log4j.net.SocketAppender
    log4j.appender.socket.Port=4560
    log4j.appender.socket.RemoteHost=localhost
    log4j.appender.socket.layout=org.apache.log4j.PatternLayout
    log4j.appender.socket.layout.ConversionPattern=%d [%-5p] [%l] %m%n
    log4j.appender.socket.ReconnectionDelay=10000
     
    # appender console
    log4j.appender.console=org.apache.log4j.ConsoleAppender
    log4j.appender.console.target=System.out
    log4j.appender.console.layout=org.apache.log4j.PatternLayout
    log4j.appender.console.layout.ConversionPattern=%d [%-5p] [%l] %m%n

      

     

    打印log测试:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class SpringbootElkApplicationTests {
     
        @Test
        public void contextLoads() {
        }
     
        private Logger logger = Logger.getLogger(getClass());
     
        @Test
        public void test() throws Exception {
     
            for(int i=0;i<100;i++) {
                logger.info("输出info  ");
                logger.debug("输出debug+skkkw嗡嗡嗡kw");
                logger.error("输出error  嗡嗡嗡我");
            }
        }
     
     
    }

      

  • 相关阅读:
    MAC OS下安装Minizip
    MAC OS下安装pkg_config
    计算机图形学-几何变换
    计算机图形学-图形系统
    Unix&Linux大学教程 读书笔记【1-3章】
    Mixins 混入选项操作
    watch监控,对比新值和旧值做出相应判断
    用.native修饰器来对外部组件进行构造器内部方法的调用以及用原生js获取构造器里的方法
    methods 方法选项
    computed 计算选项
  • 原文地址:https://www.cnblogs.com/MaxElephant/p/10232042.html
Copyright © 2020-2023  润新知