fix: robust log retrieval with stderr merging and status check
- Merged stdout and stderr in cmd_logs to capture all container output. - Added explicit check for container status when no logs are returned. - Improved feedback for empty logs in running containers. - Fixed "No logs" placeholder when container writes exclusively to stderr.
This commit is contained in:
16
install.sh
16
install.sh
@@ -332,18 +332,18 @@ async def cmd_restart(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
async def cmd_logs(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
async def cmd_logs(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
if not update.effective_user or not _ok(update.effective_user.id): return
|
if not update.effective_user or not _ok(update.effective_user.id): return
|
||||||
|
|
||||||
running = await proxy_running()
|
is_running = await proxy_running()
|
||||||
if not running:
|
if not is_running:
|
||||||
text = "❌ <b>Контейнер не найден или остановлен.</b>"
|
text = "❌ <b>Прокси-контейнер не запущен или не найден.</b>"
|
||||||
else:
|
else:
|
||||||
# Запрашиваем 50 строк и объединяем выводы
|
# Запрашиваем 50 строк и объединяем выводы (out и err)
|
||||||
code, out, err = await sh("docker", "logs", "--tail", "50", CONTAINER_NAME, timeout=15)
|
code, out, err = await sh("docker", "logs", "--tail", "50", CONTAINER_NAME, timeout=15)
|
||||||
combined_logs = (out.strip() + "\n" + err.strip()).strip()
|
full_logs = (out.strip() + "\n" + err.strip()).strip()
|
||||||
|
|
||||||
if not combined_logs:
|
if not full_logs:
|
||||||
text = "📋 <b>Контейнер запущен, но логи пока пусты.</b>\n<i>Попробуйте подключиться к прокси, чтобы появились записи.</i>"
|
text = "📋 <b>Контейнер запущен, но записей в логах пока нет.</b>\n<i>Попробуйте подключиться к прокси, чтобы данные появились.</i>"
|
||||||
else:
|
else:
|
||||||
text = f"<pre>{html.escape(combined_logs)}</pre>"
|
text = f"<pre>{html.escape(full_logs)}</pre>"
|
||||||
|
|
||||||
kb = InlineKeyboardMarkup([[InlineKeyboardButton("◀️ Меню", callback_data="menu_main")]])
|
kb = InlineKeyboardMarkup([[InlineKeyboardButton("◀️ Меню", callback_data="menu_main")]])
|
||||||
if update.callback_query:
|
if update.callback_query:
|
||||||
|
|||||||
Reference in New Issue
Block a user