使用日志采集的话,先安装es 、kinaba …
可以参考我之前的文章:https://blog.csdn.net/weixin_38650898/article/details/117731166
logstash下载安装
我下载的版本是:windows 的8.1.2,其他版本自己采坑哦。。
下载地址:https://www.elastic.co/cn/downloads/logstash
修改配置文件:logstash.conf ,没有自己建一个
input {
file {
# 这个路径还必须用/这个斜杆,不然找不到文件的
path => ["D:/xiao7_workspace/xiao7/learning-example/springboot-example/logs/springboot-example.2022-03-24.log"]
start_position => "beginning"
type => "iis_log_1"
}
}
output {
# elasticsearch { hosts => ["localhost:9200"] }
stdout { codec => rubydebug }
}
需要注意的是,我这个版本的启动时要么配置全路径,要么只能放在logstash-8.1.2目录下
启动logstash,启动了最好看下日志,可能会各种错~~,如果是jdk 的问题,可以去找setup.bat 这个文件配置下加载的jdk
D:\env\logstash-8.1.2\bin>logstash -f logstash.conf
结果就采集到的信息了
SpringBoot整合logstash、es采集日志
先加个配置文件:logstash-collect.conf
input {
tcp {
host => "127.0.0.1"
port => 4567
mode => "server"
tags => ["tags"]
codec => json_lines
}
}
output {
elasticsearch {
hosts =>"127.0.0.1:9200"
index =>"%{[appName]}"
}
}
配置一下项目依赖、日志配置
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<property name="PROJECT_NAME" value="springboot-example"/>
<property name="LOG_HOME" value="D:/xiao7_workspace/xiao7/learning-example/springboot-example/logs"/>
<logger name="com.alibaba.dubbo" level="INFO"/>
<appender name="dailyFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/${PROJECT_NAME}.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>15</MaxHistory>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder>
<pattern>%d %-5p %t [%C{1}:%L] - %m%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="errorFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/${PROJECT_NAME}.error.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>15</MaxHistory>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>%d %-5p %t [%C{1}:%L] - %m%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>127.0.0.1:4567</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
<customFields>{"appName": "spring-boot-example"}</customFields>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="dailyFile"/>
<appender-ref ref="errorFile"/>
<appender-ref ref="logstash"/>
</root>
</configuration>
然后启动服务,然后打开kibana ,创建一个索引查询的面板 最后就能看到具体的日志了。。。。
fileBeat实现日志采集
参考文档:https://www.cnblogs.com/ff111/p/15952314.html
还没试,先放着。
|