p2pfl.management.logger.logger module¶
P2PFL Logger.
Note
Not all is typed because the python logger is not typed (yep, is a TODO…).
- class p2pfl.management.logger.logger.ColoredFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]¶
Bases:
Formatter
Formatter that adds color to the log messages.
- exception p2pfl.management.logger.logger.NodeNotRegistered[source]¶
Bases:
Exception
Exception raised when a node is not registered.
- class p2pfl.management.logger.logger.P2PFLogger(nodes=None, disable_locks=False)[source]¶
Bases:
object
Class that manages the node logging (not a singleton).
- Parameters:
p2pfl_web_services – The P2PFL Web Services to log and monitor the nodes remotely.
nodes (
dict
[str
,dict
[str
,Any
]] |None
)disable_locks (
bool
)
- add_handler(handler)[source]¶
Add a handler to the logger.
- Parameters:
handler (
Handler
) – The logger handler.- Return type:
None
- connect(**kwargs)[source]¶
Establish connection/setup for the logger.
This method should be overridden by loggers that require connection setup. By default, it does nothing.
- Parameters:
**kwargs (
Any
) – Connection parameters specific to each logger type.- Return type:
None
- critical(node, message)[source]¶
Log a critical message.
- Parameters:
node (
str
) – The node name.message (
str
) – The message to log.
- Return type:
None
- debug(node, message)[source]¶
Log a debug message.
- Parameters:
node (
str
) – The node name.message (
str
) – The message to log.
- Return type:
None
- error(node, message)[source]¶
Log an error message.
- Parameters:
node (
str
) – The node name.message (
str
) – The message to log.
- Return type:
None
- experiment_finished(node)[source]¶
Notify the experiment end.
- Parameters:
node (
str
) – The node address.- Return type:
None
- experiment_started(node, experiment)[source]¶
Notify the experiment start.
- Parameters:
node (
str
) – The node address.experiment (
Experiment
) – The experiment.
- Return type:
None
- experiment_updated(node, experiment)[source]¶
Notify the round end.
- Parameters:
node (
str
) – The node address.experiment (
Experiment
) – The experiment to update.
- Return type:
None
- finish()[source]¶
Finish any logging activities, like closing a W&B run.
This method is a placeholder and is meant to be implemented by a decorator. By default, it does nothing.
- Return type:
None
- get_global_logs()[source]¶
Get the logs.
- Parameters:
node – The node name.
exp – The experiment name.
- Return type:
dict
[str
,dict
[str
,dict
[str
,list
[tuple
[int
,float
]]]]]- Returns:
The logs.
- get_level_name(lvl)[source]¶
Get the logger level name.
- Parameters:
lvl (
int
) – The logger level.- Return type:
str
- Returns:
The logger level name.
- get_local_logs()[source]¶
Get the logs.
- Parameters:
node – The node name.
exp – The experiment name.
- Return type:
dict
[str
,dict
[int
,dict
[str
,dict
[str
,list
[tuple
[int
,float
]]]]]]- Returns:
The logs.
- get_messages(direction='all', node=None, cmd=None, round_num=None, limit=None)[source]¶
Get communication messages with optional filtering.
- Parameters:
direction (
str
) – Filter by message direction (“all”, “sent”, or “received”).node (
str
|None
) – Filter by node address (optional).cmd (
str
|None
) – Filter by command type (optional).round_num (
int
|None
) – Filter by round number (optional).limit (
int
|None
) – Limit the number of messages returned per node (optional).
- Return type:
list
[dict
[str
,Any
]]- Returns:
A flat list of message dictionaries. Each message includes a ‘direction’ field indicating whether it was ‘sent’ or ‘received’.
- get_nodes()[source]¶
Get the registered nodes.
- Return type:
dict
[str
,dict
[Any
,Any
]]- Returns:
The registered nodes.
- get_system_metrics()[source]¶
Get the system metrics.
- Return type:
dict
[datetime
,dict
[str
,float
]]- Returns:
The system metrics.
- info(node, message)[source]¶
Log an info message.
- Parameters:
node (
str
) – The node name.message (
str
) – The message to log.
- Return type:
None
- log(level, node, message)[source]¶
Log a message.
- Parameters:
level (
int
) – The log level.node (
str
) – The node name.message (
str
) – The message to log.
- Return type:
None
- log_communication(node, direction, cmd, source_dest, package_type, package_size, round_num=None, additional_info=None)[source]¶
Log a communication event.
- Parameters:
node (
str
) – The node address.direction (
str
) – Direction of communication (“sent” or “received”).cmd (
str
) – The command or message type.source_dest (
str
) – Source (if receiving) or destination (if sending) node.package_type (
str
) – Type of package (“message” or “weights”).package_size (
int
) – Size of the package in bytes (if available).round_num (
int
|None
) – The federated learning round number (if applicable).additional_info (
dict
[str
,Any
] |None
) – Additional information as a dictionary.
- Return type:
None
- log_metric(addr, metric, value, step=None, round=None)[source]¶
Log a metric.
- Parameters:
addr (
str
) – The node name.metric (
str
) – The metric to log.value (
float
) – The value.step (
int
|None
) – The step.round (
int
|None
) – The round.
- Return type:
None
- register_node(node)[source]¶
Register a node.
- Parameters:
node (
str
) – The node address.- Return type:
None
- reset()[source]¶
Reset the logger state between experiments.
This clears all stored metrics, messages, and system logs while keeping the logger configuration and handlers intact.
- Return type:
None
- set_level(level)[source]¶
Set the logger level.
- Parameters:
level (
int
|str
) – The logger level.- Return type:
None