Make Event logging more useful by default
Log messages like: ChassisGatewayAgentEvent : Matched Chassis, create, None None are not particularly useful. This adds a default repr to RowEvents and also a Row stringifier (which eventually could go in the ovs lib). Subclasses of RowEvent that rely on custom match functions should write their own __repr__ methods. Change-Id: Ice22858df465b37b973718be718673aab46193ce
This commit is contained in:
parent
c52e53b1bc
commit
ceea8a23f1
|
@ -40,8 +40,8 @@ class RowEvent(ovsdb_event.RowEvent): # pylint: disable=abstract-method
|
|||
return False
|
||||
if not self.match_fn(event, row, old):
|
||||
return False
|
||||
LOG.debug("%s : Matched %s, %s, %s %s", self.event_name, self.table,
|
||||
event, self.conditions, self.old_conditions)
|
||||
LOG.debug("Matched %s: %r to row=%s old=%s", event.upper(), self,
|
||||
idlutils.row2str(row), idlutils.row2str(old) if old else '')
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -310,3 +310,14 @@ def db_replace_record(obj):
|
|||
elif isinstance(obj, api.Command):
|
||||
obj = obj.result
|
||||
return obj
|
||||
|
||||
|
||||
def row2str(row):
|
||||
"""Get a string representation of a Row"""
|
||||
|
||||
# This is not a repr, as the Row object takes a dict of Datum objects and
|
||||
# we don't really want to deal with those, just what the Python values are.
|
||||
# Row foreign keys are printed as their UUID
|
||||
return "%s(%s)" % (row._table.name, ", ".join(
|
||||
"%s=%s" % (col, idl._row_to_uuid(getattr(row, col)))
|
||||
for col in row._table.columns if hasattr(row, col)))
|
||||
|
|
|
@ -53,6 +53,11 @@ class RowEvent(object):
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(events=%r, table=%r, conditions=%r, old_conditions=%r)" % (
|
||||
self.__class__.__name__, self.events, self.table, self.conditions,
|
||||
self.old_conditions)
|
||||
|
||||
@abc.abstractmethod
|
||||
def matches(self, event, row, old=None):
|
||||
"""Test that `event` on `row` matches watched events
|
||||
|
|
Loading…
Reference in New Issue