Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Add Log File Support to Agno for Easier Monitoring & Debugging #2069

Open
2 of 3 tasks
kolhesamiksha opened this issue Feb 10, 2025 · 1 comment
Open
2 of 3 tasks
Labels
enhancement New feature or request

Comments

@kolhesamiksha
Copy link

Problem Description

I was comparing the performance of normal chunking methods and agentic chunking methods. While evaluating different packages for production, I explored Agno to measure performance, token usage, and cost analysis. Unlike LangChain, which provides callbacks to track token usage, Agno primarily logs execution traces internally. This made it difficult to retrieve cost-related information directly.

To address this, I modified the Timer, Metrics, and OpenAIChat.response() functions to capture the total LLM calls and cost calculations. However, Agno currently does not provide an easy way for users to access logs.

Since Agno logs everything internally, users should have the option to store logs in a configurable log file for debugging and cost analysis.

Proposed Solution

To improve usability and debugging, I propose adding a file-based logging mechanism to Agno’s logging system. This would allow users to:

Define a custom log file path using the ENV variable AGNO_LOG_FILE.

If no log file is explicitly set, store logs in the root directory where the package is used.

Code: Modification path: agno/libs/agno/agno/utils/log.py

Proposed Updation Code:

import logging
from os import getenv
from rich.logging import RichHandler

LOGGER_NAME = "agno"

def get_logger(logger_name: str, log_file: str = None) -> logging.Logger:
    """
    Creates and configures a logger with RichHandler for console output and optionally logs to a file.
    
    :param logger_name: Name of the logger.
    :param log_file: Optional log file path to store logs.
    :return: Configured logger instance.
    """
    # Rich console handler
    rich_handler = RichHandler(
        show_time=False,
        rich_tracebacks=False,
        show_path=True if getenv("AGNO_API_RUNTIME") == "dev" else False,
        tracebacks_show_locals=False,
    )
    rich_handler.setFormatter(logging.Formatter(fmt="%(message)s"))

    _logger = logging.getLogger(logger_name)
    _logger.setLevel(logging.INFO)
    _logger.addHandler(rich_handler)

    # If a log file is provided, add a file handler
    if log_file:
        file_handler = logging.FileHandler(log_file, mode="a")  # Append mode
        file_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
        _logger.addHandler(file_handler)

    _logger.propagate = False
    return _logger


# Allow users to set a log file
LOG_FILE_PATH = getenv("AGNO_LOG_FILE", "agno.log")  # Default log file if not provided
logger: logging.Logger = get_logger(LOGGER_NAME, LOG_FILE_PATH)


def set_log_level_to_debug():
    """Set logger level to DEBUG."""
    _logger = logging.getLogger(LOGGER_NAME)
    _logger.setLevel(logging.DEBUG)


def set_log_level_to_info():
    """Set logger level to INFO."""
    _logger = logging.getLogger(LOGGER_NAME)
    _logger.setLevel(logging.INFO)

Alternatives Considered

After reviewing the package, I noticed Agno provides platform-based monitoring for cost and performance tracking. However, it does not expose callbacks for local debugging or detailed execution tracing, unlike LangChain Callbacks https://python.langchain.com/v0.1/docs/modules/callbacks/)

By enabling file-based logging, users can independently monitor token usage, execution time, and cost without relying solely on Agno’s platform.

Additional context

Include any extra information that might be helpful, such as:

Would you like to work on this?

We welcome contributions! Let us know if you’d like to help implement this feature.

  • Yes, I’d love to work on it!
  • I’m open to collaborating but need guidance.
  • No, I’m just sharing the idea.
@kolhesamiksha kolhesamiksha added the enhancement New feature or request label Feb 10, 2025
@monali7-d
Copy link
Contributor

Hi @kolhesamiksha

Thank you so much for using Agno and sharing your valuable input! We've added your suggestion to our community wishlist. Our team will be coming together soon to discuss it, and we’ll be sure to keep you updated on any progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants