Custom Logging
Configure the default agno.utils.log logger with a custom Python logger.
Configure the default agno.utils.log logger with a custom Python logger by calling configure_agno_logging().
The source passes only custom_default_logger, which configures the default agno.utils.log logger. Agent, team, and workflow operations use separate loggers. Pass the custom logger to all four parameters to route those operation logs through it too.
"""
Custom Logging
=============================
Example showing how to use a custom logger with Agno.
"""
import logging
from agno.agent import Agent
from agno.utils.log import configure_agno_logging, log_info
def get_custom_logger():
"""Return an example custom logger."""
custom_logger = logging.getLogger("custom_logger")
handler = logging.StreamHandler()
formatter = logging.Formatter("[CUSTOM_LOGGER] %(levelname)s: %(message)s")
handler.setFormatter(formatter)
custom_logger.addHandler(handler)
custom_logger.setLevel(logging.INFO) # Set level to INFO to show info messages
custom_logger.propagate = False
return custom_logger
# Get the custom logger we will use for the example.
custom_logger = get_custom_logger()
# Configure Agno to use our custom logger. It will be used for all logging.
configure_agno_logging(custom_default_logger=custom_logger)
# Every use of the logging function in agno.utils.log will now use our custom logger.
log_info("This is using our custom logger!")
# Now let's setup an Agent and run it.
# All logging coming from the Agent will use our custom logger.
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent()
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent.print_response("What can I do to improve my sleep?")Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openaiExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Configure every Agno logger
Replace configure_agno_logging(custom_default_logger=custom_logger) with configure_agno_logging(custom_default_logger=custom_logger, custom_agent_logger=custom_logger, custom_team_logger=custom_logger, custom_workflow_logger=custom_logger) in the saved file.
Run the example
Save the code above as custom_logging.py, then run:
python custom_logging.pyFull source: cookbook/02_agents/14_advanced/custom_logging.py