Logger is a core component designed to record and track events, errors, and other important actions during application execution. It provides valuable insights into application behavior, performance, and potential issues, helping developers troubleshoot and monitor systems effectively.In the BeeAI framework, the Logger class is an abstraction built on top of Python’s built-in logging module, offering enhanced capabilities specifically designed for AI agent workflows.
from beeai_framework.logger import Logger# Configure logger with default log level from the BEEAI_LOG_LEVEL variablelogger = Logger("app")# Log at different levelslogger.trace("Trace!")logger.debug("Debug!")logger.info("Info!")logger.warning("Warning!")logger.error("Error!")logger.fatal("Fatal!")
import { Logger, LoggerLevel } from "beeai-framework/logger/logger";// Configure logger defaultsLogger.defaults.pretty = true; // Pretty-print logs (default: false, can also be set via ENV: BEE_FRAMEWORK_LOG_PRETTY=true)Logger.defaults.level = LoggerLevel.TRACE; // Set log level to trace (default: TRACE, can also be set via ENV: BEE_FRAMEWORK_LOG_LEVEL=trace)Logger.defaults.name = undefined; // Optional name for logger (default: undefined)Logger.defaults.bindings = {}; // Optional bindings for structured logging (default: empty)// Create a child logger for your appconst logger = Logger.root.child({ name: "app" });// Log at different levelslogger.trace("Trace!");logger.debug("Debug!");logger.info("Info!");logger.warn("Warning!");logger.error("Error!");logger.fatal("Fatal!");
The logger adds a TRACE level below DEBUG for extremely detailed logging:
Python
# Configure a logger with a specific levellogger = Logger("app", level="TRACE") # Or use logging constants like logging.DEBUG# Log with the custom TRACE levellogger.trace("This is a very low-level trace message")
The Logger seamlessly integrates with agents in the framework. Below is an example that demonstrates how logging can be used in conjunction with agents and event emitters.