forked from DiamondLightSource/mx-bluesky
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DiamondLightSource/hyperion#1373 from DiamondLight…
…Source/487_improve_logging_formatting (Dodal DiamondLightSource/hyperion#487) Improve logging formatting for documents
- Loading branch information
Showing
9 changed files
with
43 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 15 additions & 4 deletions
19
src/hyperion/external_interaction/callbacks/logging_callback.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_for_log(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_for_log(doc)}") | ||
|
||
def descriptor(self, doc): | ||
LOGGER.info(f"DESCRIPTOR: {doc}") | ||
LOGGER.info(f"DESCRIPTOR: {format_doc_for_log(doc)}") | ||
|
||
def event(self, doc): | ||
LOGGER.info(f"EVENT: {doc}") | ||
LOGGER.info(f"EVENT: {format_doc_for_log(doc)}") | ||
return doc | ||
|
||
def stop(self, doc): | ||
LOGGER.info(f"STOP: {doc}") | ||
LOGGER.info(f"STOP: {format_doc_for_log(doc)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters