AleksanderWWW / abcd-graph

MIT License
3 stars 0 forks source link

Add logging #9

Closed AleksanderWWW closed 2 months ago

AleksanderWWW commented 2 months ago

What this PR does

Introduce a logging functionality that will help us keep track of what is happening during the graph generation process.

>>> generate_abcd(params=params, n=1_000_000)  # no logging by default

>>> generate_abcd(params=params, n=1_000_000, logger=True)

[abcd-graph] - 2024-04-22 19:37:08,427 - INFO - Generating ABCD graph
[abcd-graph] - 2024-04-22 19:37:08,427 - INFO - Building degrees
[abcd-graph] - 2024-04-22 19:37:08,497 - INFO - Building community sizes
[abcd-graph] - 2024-04-22 19:37:08,508 - INFO - Building communities
[abcd-graph] - 2024-04-22 19:37:08,544 - INFO - Assigning degrees
[abcd-graph] - 2024-04-22 19:37:09,537 - INFO - Splitting degrees
[abcd-graph] - 2024-04-22 19:37:11,143 - INFO - Building community edges
[abcd-graph] - 2024-04-22 19:37:14,460 - INFO - Building background edges
[abcd-graph] - 2024-04-22 19:37:16,356 - INFO - ABCD graph generated

You can also write your own logger (e.g. to write log to a file) by inheriting from ABCDLogger and overwritting its abstract methods:

from abcd_graph.logger import ABCDLogger

class MyLogger(ABCDLogger):
    ...  # overwrite 'debug', 'info', 'warning', 'error' and 'critical' methods

Use your custom logger in the generation function

>>> generate_abcd(params=params, n=1_000_000, logger=MyLogger())