在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(