Logstash数据源为日志文件操作

本文档介绍了如何在Springboot应用中整合ELK栈,并详细讲述了如何配置Logstash从日志文件中收集数据。首先通过Python脚本模拟日志生成,然后修改Logstash配置文件添加文件数据源,接着更新Docker容器的日志挂载目录,最后重启Logstash容器并验证结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Springboot整合ELK基础上进行

一、模拟日志

1. 在D:\usr\local\bin\start目录下编写python脚本save_log.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import datetime
import threading

import os

# 递归级联创建的目录
path = "D:/usr/local/logs"
if not os.path.exists(path):
    os.makedirs(path)

# 方法1: 此方法文件夹不存在会报错:FileNotFoundError: [Errno 2] No such file or directory
with open('D:/usr/local/logs/spring.log', mode='a+', encoding='utf-8') as f:
    now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
    thread_id = threading.currentThread().native_id
    log_str = f'{now} DEBUG {thread_id} --- [scheduling-1] org.jooq.tools.LoggerListener            : ' \
              'Executing query          : select id from user'
    f.writelines(f'{log_str}\n')
    f.close()
    print(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值