Learn how to use custom loggers in your Agno setup.
You can provide your own loggers 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.
import loggingfrom agno.agent import Agentfrom agno.team import Teamfrom agno.utils.log import configure_agno_logging, log_info# Setting 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) # Set level to INFO to show info messagescustom_logger.propagate = False# 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!")# Setting up an example Agentagent = Agent()# Now let's setup an example Team and run it.# All logging will use our custom logger.team = Team(members=[agent])team.print_response("What can I do to improve my sleep?")
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.agent 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
These loggers will be automatically picked up if they are set.