Supervisely has a logger. It is a wrapper over Python's built-in package.
First thing we need to do is install Supervisely Python SDK to your environment:
pip install supervisely
Let's take the code from Part 1 as a basis and add a logger:
import supervisely_lib as sly
worlds = ['Westeros', 'Azeroth', 'Middle Earth', 'Narnia']
sly_logger = sly.logger
for world in worlds:
sly_logger.info(f'Hello {world}!')
Step 2 — Use [try: except] with traceback
To handle errors, you can use the [try: except] construction
src/main.py
import supervisely_lib as sly
worlds = ['Westeros', 'Azeroth', 'Middle Earth', 'Narnia']
sly_logger = sly.logger
try:
for world in worlds:
sly_logger.info(f'Hello {world}!')
if 'Our World' not in worlds:
raise ValueError(f"Can't find Our World")
except Exception as ex:
sly_logger.warning(ex)