spring boot 项目中配置logback同步ELK(通过kafka同步到logstack再同步到ES)

最近项目中配置了logback每次日志都必须登录到服务端去看,就想着吧logback的日志同步到ES中,通过kibana去查询日志进行分析,
一下是logback同步日志到ELK中的具体配置,
logstach配置

input {
  kafka {
    topics => "xxxx-datagaea-dbengine-log-topic"
    bootstrap_servers => "192.168.0.117:29092"
    group_id => "datagaea_dbengine"
    client_id => "datagaea_dbengine"
    consumer_threads => 1
    decorate_events => true
    codec => "json"
    add_field => {
      "[@metadata][type]" => "xxxx-datagaea-dbengine-log"
    }
  }
}#
filter {#}
output {
  if [@metadata][type] == "xxxx-datagaea-dbengine-log" {
    elasticsearch {
      hosts => ["192.168.0.117:29200"]
      index => "xxxx-datagaea-dbengine-log-dev"
    }
  }
}

logback配置信息

  >
    -8" class="net.logstash.logback.encoder.LogstashEncoder">
      >{"appName":"xxxx-datagaea-core"}>
      >true>
      >true>
      >
        >30>
        >true>
      >
    >
    >potato-datagaea-core-log-topic>
    >
    >
    >bootstrap.servers=192.168.0.117:29092>
  >
>
    >
      >
        -ref ref="STDOUT"/>
      >
    >
  >
  >
    >
      >
        -ref ref="STDOUT"/>
        -ref ref="FILE_ASYNC"/>
        -ref ref="kafkaAppender_dev"/>
      >
    >
  >

  >
    >
      >
        -ref ref="STDOUT"/>
        -ref ref="FILE_ASYNC"/>
        -ref ref="ERROR_FILE"/>
        <!-- -ref ref="EMAIL"/>-->
      
    >
  >

  >
    >
      >
        -ref ref="FILE_ASYNC"/>
        -ref ref="ERROR_FILE"/>
        <!-- ref="EMAIL"/>-->
      
    >
  >

下面的if是分环境配置信息,验证信息的话,需要验证日志是否同步到kafka内,通过kafka tools 工具进行验证,还需要引入相应的jar包,一下是pom.xml的配置

 >
      >ch.qos.logback>
      >logback-classic>
      >1.2.3>
    >
    >
      >ch.qos.logback>
      >logback-core>
      >1.2.3>
    >
    >
      >com.github.danielwegener>
      >logback-kafka-appender>
      >0.2.0-RC2>
    >
    >
      >net.logstash.logback>
      >logstash-logback-encoder>
      >6.3>
    >

你可能感兴趣的:(spring,boot)