Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions dsync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
ObjectNotFound,
)

_logger = structlog.get_logger()


class DSyncFlags(enum.Flag):
"""Flags that can be passed to a sync_* or diff_* call to affect its behavior."""
Expand All @@ -57,6 +55,13 @@ class DSyncFlags(enum.Flag):

SKIP_UNMATCHED_BOTH = SKIP_UNMATCHED_SRC | SKIP_UNMATCHED_DST

LOG_UNCHANGED_RECORDS = enum.auto()
"""If this flag is set, a log message will be generated during synchronization for each model, even unchanged ones.

By default, when this flag is unset, only models that have actual changes to synchronize will be logged.
This flag is off by default to reduce the default verbosity of DSync, but can be enabled when debugging.
"""


class DSyncModel(BaseModel):
"""Base class for all DSync object models.
Expand Down Expand Up @@ -339,7 +344,7 @@ def __init__(self, name=None):
Subclasses should be careful to call super().__init__() if they override this method.
"""
self._data = defaultdict(dict)
self._log = _logger.new(dsync=self)
self._log = structlog.get_logger().new(dsync=self)

# If the type is not defined, use the name of the class as the default value
if self.type is None:
Expand Down Expand Up @@ -454,6 +459,9 @@ def _sync_from_diff_element(
raise ObjectNotDeleted(f"Failed to delete {object_class.get_type()} {element.keys} - not found!")
obj = obj.delete()
log.info("Deleted successfully", status="success")
else:
if flags & DSyncFlags.LOG_UNCHANGED_RECORDS:
log.debug("No action needed", status="success")
except ObjectCrudException as exception:
log.error(str(exception), status="error")
if not flags & DSyncFlags.CONTINUE_ON_FAILURE:
Expand Down