Use this file to discover all available pages before exploring further.
You can provide your own logging configuration to Agno, to be used instead of the default ones.This can be useful if you need your system to log in any specific format.
You can configure Agno to use your own logging configuration by using the configure_agno_logging function.
import loggingfrom agno.agent import Agentfrom agno.utils.log import configure_agno_logging, log_info# Set up a custom loggercustom_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)custom_logger.propagate = False# Configure Agno to use the custom loggerconfigure_agno_logging(custom_default_logger=custom_logger)# All logging will now use the custom loggerlog_info("This is using our custom logger!")agent = Agent()agent.print_response("What is 2+2?")
You can configure Agno to log to a file instead of the console:
import loggingfrom pathlib import Pathfrom agno.agent import Agentfrom agno.utils.log import configure_agno_logging, log_info# Create a custom logger that writes to a filecustom_logger = logging.getLogger("file_logger")# Ensure tmp directory existslog_file_path = Path("tmp/log.txt")log_file_path.parent.mkdir(parents=True, exist_ok=True)# Use FileHandler to write to filehandler = logging.FileHandler(log_file_path)formatter = logging.Formatter("%(levelname)s: %(message)s")handler.setFormatter(formatter)custom_logger.addHandler(handler)custom_logger.setLevel(logging.INFO)custom_logger.propagate = False# Configure Agno to use the file loggerconfigure_agno_logging(custom_default_logger=custom_logger)# All logs will be written to tmp/log.txtlog_info("This is using our file logger!")agent = Agent()agent.print_response("Tell me a fun fact")
You can configure different loggers for your Agents, Teams and Workflows:
import loggingfrom agno.agent import Agentfrom agno.team import Teamfrom agno.workflow import Workflowfrom agno.workflow.step import Stepfrom agno.utils.log import configure_agno_logging, log_info# Create custom loggers for different componentscustom_agent_logger = logging.getLogger("agent_logger")custom_team_logger = logging.getLogger("team_logger")custom_workflow_logger = logging.getLogger("workflow_logger")# Configure handlers and formatters for eachfor logger in [custom_agent_logger, custom_team_logger, custom_workflow_logger]: handler = logging.StreamHandler() handler.setFormatter(logging.Formatter("[%(name)s] %(levelname)s: %(message)s")) logger.addHandler(handler) logger.setLevel(logging.INFO) logger.propagate = False# Workflow logs at DEBUG level when debug_mode is enabled# Set workflow logger to DEBUG to see these logscustom_workflow_logger.setLevel(logging.DEBUG)# Apply the configurationconfigure_agno_logging( custom_default_logger=custom_agent_logger, custom_agent_logger=custom_agent_logger, custom_team_logger=custom_team_logger, custom_workflow_logger=custom_workflow_logger,)# All logging will now use the custom agent logger by defaultlog_info("Using custom loggers!")# Create agent and teamagent = Agent()team = Team(members=[agent])# Agent will use custom_agent_loggeragent.print_response("What is 2+2?")# Team will use custom_team_loggerteam.print_response("Tell me a short joke")# Workflow will use custom_workflow_loggerworkflow = Workflow( debug_mode=True, steps=[Step(name="step1", agent=agent)])workflow.print_response("Tell me a fun fact")
As it’s conventional in Python, you can also provide custom loggers just by setting loggers with specific names. This is useful if you want to set them up using configuration files.Agno automatically recognizes and uses these logger names:
agno will be used for all Agent logs
agno-team will be used for all Team logs
agno-workflow will be used for all Workflow logs
import loggingfrom agno.agent import Agentfrom agno.team import Teamfrom agno.workflow import Workflowfrom agno.workflow.step import Step# Set up named loggers BEFORE creating agents/teams/workflowslogger_configs = [ ("agno", "agent.log"), ("agno-team", "team.log"), ("agno-workflow", "workflow.log"),]for logger_name, log_file in logger_configs: logger = logging.getLogger(logger_name) logger.setLevel(logging.INFO) handler = logging.FileHandler(log_file) handler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) logger.addHandler(handler) logger.propagate = False# Agno will automatically detect and use these loggersagent = Agent()agent.print_response("Hello from agent!") # Agent logs will go to agent.logteam = Team(members=[agent])team.print_response("Hello from team!") # Team logs will go to team.log# Workflow requires debug mode to use the workflow loggerworkflow = Workflow( debug_mode=True, steps=[Step(name="step1", agent=agent)])workflow.run("Hello from workflow!") # Workflow logs will go to workflow.log