refactor: agents inherit logger from BaseAgent

Created a class `BaseAgent`, from which all agents inherit. They get
assigned a logger with a nice name (something like
`control_backend.agents.AgentName`).

The BDI core takes care of its own logger, as bdi is still a module.

ref: N25B-241
This commit is contained in:
2025-11-04 20:48:55 +01:00
parent d43cb9394a
commit a98018ddda
15 changed files with 174 additions and 159 deletions

View File

@@ -0,0 +1,18 @@
import logging
from spade.agent import Agent
class BaseAgent(Agent):
"""
Base agent class for our agents to inherit from.
This ensures that all agents have a logger.
"""
logger: logging.Logger
# Whenever a subclass is initiated, give it the correct logger
def __init_subclass__(cls, **kwargs) -> None:
super().__init_subclass__(**kwargs)
cls.logger = logging.getLogger(__package__).getChild(cls.__name__)