Debugging and Logging¶
Bluesky uses Python logging framework. See below for a list of the names of the loggers it publishes to.
If the RunEngine is “hanging,” running slowly, or repeatedly encountering an error, it is useful to know exactly where in the plan the problem is occurring. To follow the RunEngine’s progress through the plan, crank up the verbosity of the logging.
To direct the output to a file instead of to the screen:
from bluesky import set_handler set_handler(file='debugging_bluesky.txt')
Here is the complete list of loggers used by bluesky.
'bluesky'— the logger to which all bluesky log messages propagate
'bluesky.RE'— Messages from a RunEngine. INFO-level notes state changes. DEBUG-level notes when each message from a plan is about to be processed, when a document has been emitted to subscribed callbacks, and when a status object has completed.
'bluesky.RE.<id>'— Messages from a specific RunEngine instance, disambiguating the (rare) case where there are multiple RunEngine instances in the same process. This is the logger that the accessor
'bluesky.RE.<id>.msg'— DEBUG-level notes when each message from a plan is about to be processed.
By default, bluesky prints log messages to the standard out by adding a
logging.StreamHandler to the
'bluesky' logger at import time. You
can, of course, configure the handlers manually in the standard fashion
supported by Python. But a convenience function
makes it easy to address common cases.
See the Examples section below.
set_handler(file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, datefmt='%H:%M:%S', color=True)¶
Set a new handler on the
This function is run at import time with default paramters. If it is run again by the user, the handler from the previous invocation is removed (if still present) and replaced.
- file : object with
writemethod or filename string
- datefmt : string
Date format. Default is
- color : boolean
Use ANSI color codes. True by default.
- handler : logging.Handler
The handler, which has already been added to the ‘bluesky’ logger.
Log to a file.
Include the date along with the time. (The log messages will always include microseconds, which are configured separately, not as part of ‘datefmt’.)
>>> set_handler(datefmt="%Y-%m-%d %H:%M:%S")
Turn off ANSI color codes.
- file : object with