Beispiel #1
0
class OlogCallback(CallbackBase):
    """Example callback to customize the logbook.

    This callback publishes the most recent IPython command (which of course
    is not guaranteed to be the one that initiated the run in question) and
    the full RunStart Document.

    Example
    -------
    # add this callback to the run engine
    >>> gs.RE.subscribe(OlogCallback(), 'start')
    # turn off the default logger
    >>> gs.RE.logbook = None
    """
    def __init__(self, logbook):
        self.logbook = logbook
        from pyOlog import SimpleOlogClient
        self.client = SimpleOlogClient()
        # Check at init time we are in an IPython session.
        from IPython import get_ipython  # noqa: F401

    def start(self, doc):
        from IPython import get_ipython
        commands = list(get_ipython().history_manager.get_range())
        document_content = ('%s: %s\n\n'
                            'RunStart Document\n'
                            '-----------------\n'
                            '%s' %
                            (doc['scan_id'], commands[-1][2], pformat(doc)))
        olog_status = self.client.log(document_content, logbooks=self.logbook)
        logger.debug('client.log returned %s' % olog_status)
        super().start(doc)
Beispiel #2
0
class OlogCallback(CallbackBase):
    """Example callback to customize the logbook.

    This callback publishes the most recent IPython command (which of course
    is not guaranteed to be the one that initiated the run in question) and
    the full RunStart Document.

    Example
    -------
    # add this callback to the run engine
    >>> gs.RE.subscribe(OlogCallback(), 'start')
    # turn off the default logger
    >>> gs.RE.logbook = None
    """
    def __init__(self, logbook):
        self.logbook = logbook
        from pyOlog import SimpleOlogClient
        self.client = SimpleOlogClient()
        # Check at init time we are in an IPython session.
        from IPython import get_ipython

    def start(self, doc):
        from IPython import get_ipython
        commands = list(get_ipython().history_manager.get_range())
        document_content = ('%s: %s\n\n'
                            'RunStart Document\n'
                            '-----------------\n'
                            '%s' % (doc['scan_id'],
                                    commands[-1][2],
                                    pformat(doc)))
        olog_status = self.client.log(document_content, logbooks=self.logbook)
        logger.debug('client.log returned %s' % olog_status)
        super().start(doc)