fix: add bot name to stream_audio log lines

Multi-bot setups need to know which bot is streaming. Prefixes all
stream_audio log messages with [username] for clarity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
user
2026-02-22 23:15:46 +01:00
parent 3c475107e3
commit 09880624d5

View File

@@ -720,8 +720,8 @@ class MumbleBot:
pass pass
_get_vol = volume if callable(volume) else lambda: volume _get_vol = volume if callable(volume) else lambda: volume
log.info("stream_audio: starting pipeline for %s (vol=%.0f%%, seek=%.1fs)", log.info("stream_audio: [%s] starting pipeline for %s (vol=%.0f%%, seek=%.1fs)",
url, _get_vol() * 100, seek) self._username, url, _get_vol() * 100, seek)
def _build_cmd(seek_pos): def _build_cmd(seek_pos):
seek_flag = f" -ss {seek_pos:.3f}" if seek_pos > 0 else "" seek_flag = f" -ss {seek_pos:.3f}" if seek_pos > 0 else ""
@@ -817,15 +817,17 @@ class MumbleBot:
if not self._is_audio_ready(): if not self._is_audio_ready():
# Disconnected -- keep reading ffmpeg at real-time pace # Disconnected -- keep reading ffmpeg at real-time pace
if _was_feeding: if _was_feeding:
log.warning("stream_audio: connection lost, " log.warning("stream_audio: [%s] connection lost, "
"dropping frames at %d", frames) "dropping frames at %d",
self._username, frames)
_was_feeding = False _was_feeding = False
await asyncio.sleep(0.02) await asyncio.sleep(0.02)
continue continue
if not _was_feeding: if not _was_feeding:
log.info("stream_audio: connection restored, " log.info("stream_audio: [%s] connection restored, "
"resuming feed at frame %d", frames) "resuming feed at frame %d",
self._username, frames)
_was_feeding = True _was_feeding = True
# Seek: fade-out in progress # Seek: fade-out in progress
@@ -893,7 +895,8 @@ class MumbleBot:
continue continue
if frames == 1: if frames == 1:
log.info("stream_audio: first frame fed to pymumble") log.info("stream_audio: [%s] first frame fed to pymumble",
self._username)
# Keep buffer at most 1 second ahead # Keep buffer at most 1 second ahead
try: try:
@@ -910,7 +913,8 @@ class MumbleBot:
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
except (TypeError, AttributeError): except (TypeError, AttributeError):
pass pass
log.info("stream_audio: finished, %d frames", frames) log.info("stream_audio: [%s] finished, %d frames",
self._username, frames)
except asyncio.CancelledError: except asyncio.CancelledError:
# Only clear the buffer if volume is still audible -- if a # Only clear the buffer if volume is still audible -- if a
# fade-out has already driven _cur_vol to ~0 the remaining # fade-out has already driven _cur_vol to ~0 the remaining
@@ -921,11 +925,12 @@ class MumbleBot:
self._mumble.sound_output.clear_buffer() self._mumble.sound_output.clear_buffer()
except Exception: except Exception:
pass pass
log.info("stream_audio: cancelled at frame %d (vol=%.3f)", log.info("stream_audio: [%s] cancelled at frame %d (vol=%.3f)",
frames, _cur_vol) self._username, frames, _cur_vol)
raise raise
except Exception: except Exception:
log.exception("stream_audio: error at frame %d", frames) log.exception("stream_audio: [%s] error at frame %d",
self._username, frames)
raise raise
finally: finally:
try: try: