From 1813a448e87b42cfbad85e9ad68ac8c7d0bee847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B0=8F=E4=BA=91?= Date: Fri, 9 Jan 2026 18:22:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=91=BD=E4=BB=A4=E8=BE=93?= =?UTF-8?q?=E5=87=BA=EF=BC=9A=E6=98=BE=E7=A4=BA=E5=AE=8C=E6=95=B4=E7=9A=84?= =?UTF-8?q?=E6=A0=87=E5=87=86=E8=BE=93=E5=87=BA=E5=92=8C=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devops/deployer.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.devops/deployer.py b/.devops/deployer.py index 95db713..b883f70 100644 --- a/.devops/deployer.py +++ b/.devops/deployer.py @@ -54,15 +54,31 @@ class Deployer: timeout=timeout ) + # 始终输出标准输出(如果有) if result.stdout: - self.logger.debug(f"标准输出:\n{result.stdout}") + # 限制输出长度,避免日志过大 + stdout_lines = result.stdout.strip().split('\n') + if len(stdout_lines) > 50: + self.logger.info(f"标准输出 (前30行):\n" + '\n'.join(stdout_lines[:30])) + self.logger.info(f"... (省略 {len(stdout_lines) - 50} 行)") + self.logger.info(f"标准输出 (后20行):\n" + '\n'.join(stdout_lines[-20:])) + else: + self.logger.info(f"标准输出:\n{result.stdout.strip()}") if result.returncode != 0: self.logger.error(f"命令执行失败 (退出码: {result.returncode})") if result.stderr: - self.logger.error(f"错误输出:\n{result.stderr}") + # 限制错误输出长度 + stderr_lines = result.stderr.strip().split('\n') + if len(stderr_lines) > 50: + self.logger.error(f"错误输出 (前30行):\n" + '\n'.join(stderr_lines[:30])) + self.logger.error(f"... (省略 {len(stderr_lines) - 50} 行)") + self.logger.error(f"错误输出 (后20行):\n" + '\n'.join(stderr_lines[-20:])) + else: + self.logger.error(f"错误输出:\n{result.stderr.strip()}") return False + self.logger.info("命令执行成功") return True except subprocess.TimeoutExpired: self.logger.error(f"命令执行超时 (超时时间: {timeout}秒)")