networktocode / diffsync

A utility library for comparing and synchronizing different datasets.
https://diffsync.readthedocs.io/
Other
155 stars 26 forks source link

Feature to pass logger into Backend or sync_from/sync_to methods #253

Open jamesharr opened 1 year ago

jamesharr commented 1 year ago

Environment

Proposed Functionality

DiffSync currently establishes its own logger method. This feature would allow the user of DiffSync to pass in a structlog logger with some bound context data, or even pass in a structlog-compatible logger to replace the existing logger.

Below, two examples are provided. This feature would not require both be implemented.

Example usage:

First example - pass logger into backend

my_logger = structlog.get_logger().bind(
    triggered_by="user7@example.com",
    trace_id=str(uuid.uuid4()),
)

be1 = MyDiffSyncBackend(loggger=my_logger)
be1.load()
...
be1.sync_to(be2)

Second example - pass logger into sync methods

my_logger = structlog.get_logger().bind(
    triggered_by="user7@example.com",
    trace_id=str(uuid.uuid4()),
)

be1 = MyDiffSyncBackend()
be1.load()
...
be1.sync_to(be2, logger=my_logger)

Use Case