Fix logging when deleting objects

* Gather `log_json` content before `flush` -- otherwise, deleted objects
  (especially objects deleted due to cascading) cause errors when
  attempting to build `Revision` objects (since the objects are gone
  from the database and marked "dirty" in Python).