Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
U
ubains-module-test
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
郑晓兵
ubains-module-test
Commits
024d3ca5
提交
024d3ca5
authored
4月 18, 2025
作者:
陈泽健
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化get_remote_log_with_paramiko函数,增加filter_word过滤词打印日志。
上级
00ddec0b
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
5 行删除
+17
-5
base.py
预定系统/Base/base.py
+14
-3
README.md
预定系统/README.md
+3
-2
没有找到文件。
预定系统/Base/base.py
浏览文件 @
024d3ca5
...
...
@@ -1937,9 +1937,9 @@ def write_xlsx_data(xlsx_file_path, sheet_name, function_number, test_result, lo
import
paramiko
import
time
def
get_remote_log_with_paramiko
(
host
,
username
,
private_key_path
,
passphrase
,
log_path
,
num_lines
=
1000
,
timeout
=
30
):
def
get_remote_log_with_paramiko
(
host
,
username
,
private_key_path
,
passphrase
,
log_path
,
num_lines
=
1000
,
timeout
=
30
,
filter_word
=
None
):
"""
使用 Paramiko 获取远程服务器的日志文件内容.
使用 Paramiko 获取远程服务器的日志文件内容
,并通过过滤词过滤日志内容
.
Args:
host (str): 服务器 IP 地址或域名.
...
...
@@ -1949,6 +1949,7 @@ def get_remote_log_with_paramiko(host, username, private_key_path, passphrase, l
log_path (str): 日志文件路径.
num_lines (int): 要获取的日志行数 (默认 100).
timeout (int): SSH 命令执行的超时时间(秒).
filter_word (str): 过滤词,只有包含该词的日志行才会被返回 (默认 None).
Returns:
str: 获取的日志内容,如果出错返回 None.
...
...
@@ -1970,6 +1971,15 @@ def get_remote_log_with_paramiko(host, username, private_key_path, passphrase, l
output
=
stdout
.
read
()
.
decode
(
'utf-8'
)
print
(
"Successfully retrieved log content."
)
print
(
"Full log content:"
)
print
(
output
)
# 打印完整的日志内容
if
filter_word
:
filtered_output
=
"
\n
"
.
join
([
line
for
line
in
output
.
split
(
'
\n
'
)
if
filter_word
in
line
])
if
not
filtered_output
:
print
(
f
"No lines found containing the filter word: {filter_word}"
)
return
filtered_output
return
output
except
Exception
as
e
:
...
...
@@ -1984,7 +1994,8 @@ def get_remote_log_with_paramiko(host, username, private_key_path, passphrase, l
# private_key_path = "C:\\Users\\29194\\.ssh\\id_rsa" # 替换为你的私钥文件路径
# passphrase = "Ubains@123" # 替换为你的 passphrase
# log_path = "/var/www/java/api-java-meeting2.0/logs/ubains-INFO-AND-ERROR.log"
# log_content = get_remote_log_with_paramiko(host, username, private_key_path, passphrase, log_path)
# filter_word = "桌牌"
# log_content = get_remote_log_with_paramiko(host, username, private_key_path, passphrase, log_path, filter_word=filter_word)
#
# if log_content:
# print(log_content)
...
...
预定系统/README.md
浏览文件 @
024d3ca5
...
...
@@ -291,4 +291,5 @@
81.
2025-04-17
-
修复因xlsx文件读取失败导致的报错。
82.
2025-04-18
-
修复展厅巡检预定系统因页面bug导致的异常定位报错。处理优化
\ No newline at end of file
-
修复展厅巡检预定系统因页面bug导致的异常定位报错。处理优化。
-
优化get_remote_log_with_paramiko函数,增加filter_word过滤词打印日志。
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论