I am trying to debug my agent, which is written in...
# ask-ai
b
I am trying to debug my agent, which is written in Python, "using lk agent logs". But my print statements aren't showing up in the logs. How do I fix this?
✅ 1
t
Thanks for reaching out, Mat. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about why Python
print()
output isn’t showing when you run
lk agent logs
. Short answer: use the Python
logging
module (and check log level) instead of
print()
.
print()
can be buffered or not captured by the agent runtime, so it often won’t appear in
lk agent logs
. What to do: • Replace prints with logging:
Copy code
import logging
  logger = logging.getLogger("my_agent")
  logger.setLevel(logging.INFO)
  logger.info("This message will appear in lk agent logs")
• Increase verbosity if you need debug output: ◦ Start the agent with
--log-level=DEBUG
or set the
LIVEKIT_LOG_LEVEL=DEBUG
environment variable. • If you must keep
print()
during quick tests, flush stdout immediately:
print("msg", flush=True)
— but logging is the reliable solution. • Ensure you’re on LiveKit Agents SDK v1.5.0 or newer for enhanced logging support. If you want, paste a short snippet of your agent startup/logging code and I’ll point out exactly where to change it. Sources: Where to find your Agent Logs | LiveKit, with interactive elements