runs

Logs

Automatic logging

The client can be interegrated with the logging package to stream the logs into the lab. The documentation below explains how to easily track your logs.

Add an observer

If you are already using logging in your workflow, the integration will be very simple. Instead of creating the logger with logging.getLogger(), use run.add_log_stream(). It attaches a stream handler to your logger and returns the logger object that you may use to directly write on this stream. Note that if you lose reference to the logger object, you may reload it using the logging.getLogger(), or call again run.add_log_stream().

from pyhectiqlab import Run

run = Run(name="Logging example", project="lab/demo")
logger = run.add_log_stream()
logger.info("Hello world")

Remove an observer

If you want to stop streaming the logs, use run.remove_log_stream(). You can restore the stream by executing run.add_log_stream back.

# Stop logging the stream
run.remove_log_stream()

# Start again
run.add_log_stream()

Error handling

When a run is used within a script (instead of a jupyter notebook), the error traceback will automatically be pushed to the lab and assigned the run a failed status. If the exception is a KeyboardInterupt, the status will be changed to stopped.

# main.py
if __name__ == "__main__":
    run = Run(name="With traceback", project="lab/demo")
    assert False, "This error is automatically sent to the server."
python main.py

Methods

pyhectiqlab.Run

Run.add_log_stream(logger_name: str = None, format: str = '%(asctime)s - %(levelname)s - %(message)s', level: int = 30)
Start observing the log stream and pushing the logs in the lab. The method outputs a logger object.

Parameters

PropertyTypeDefaultDescription
logger_namestrNoneIf specified, the name of the log stream that will be observed. If not specified, the root logging is be observed.
formatstr'%(asctime)s - %(levelname)s - %(message)s'Optional log format.
levelint30Minimum logging level. See logging levels.
Run.remove_log_stream(logger_name: str = None)
Stop observing a specific log stream.

Parameters

PropertyTypeDefaultDescription
logger_namestrNoneIf specified, the name of the log stream that will be observed. If not specified, the root stream will be remove.
Run.clear_logs()
Clear the all the log streams saved in the cloud.

Parameters

PropertyTypeDefaultDescription