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:
18
src/control_backend/agents/base.py
Normal file
18
src/control_backend/agents/base.py
Normal 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__)
|
||||
Reference in New Issue
Block a user