Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

(Dodal #487) Improve logging formatting for documents #1373

Merged
merged 9 commits into from
May 16, 2024
Next Next commit
(#487) Improve logging formatting for documents
d-perl committed May 10, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
coreyja Corey Alexander
commit 611a7b1e5382aad1347de9c540c8483e3619e427
19 changes: 15 additions & 4 deletions src/hyperion/external_interaction/callbacks/logging_callback.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import json

from bluesky.callbacks import CallbackBase

from hyperion.log import LOGGER


class _BestEffortEncoder(json.JSONEncoder):
def default(self, o):
return repr(o)


def _format(doc):
return json.dumps(doc, indent=2, cls=_BestEffortEncoder)


class VerbosePlanExecutionLoggingCallback(CallbackBase):
def start(self, doc):
LOGGER.info(f"START: {doc}")
LOGGER.info(f"START: {_format(doc)}")

def descriptor(self, doc):
LOGGER.info(f"DESCRIPTOR: {doc}")
LOGGER.info(f"DESCRIPTOR: {_format(doc)}")

def event(self, doc):
LOGGER.info(f"EVENT: {doc}")
LOGGER.info(f"EVENT: {_format(doc)}")
return doc

def stop(self, doc):
LOGGER.info(f"STOP: {doc}")
LOGGER.info(f"STOP: {_format(doc)}")