Skip to content

Commit b0f3ca3

Browse files
committed
prevent logger from bubbling up in notebook
1 parent 62baead commit b0f3ca3

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

pylabrobot/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def setup_logger(log_dir: Optional[Union[Path, str]], level: int):
5555
fh.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
5656
logger.addHandler(fh)
5757

58+
logger.propagate = False
59+
5860

5961
def configure(cfg: Config):
6062
"""Configure pylabrobot."""

pylabrobot/io/usb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ async def setup(self):
316316
if len(devices) == 0:
317317
raise RuntimeError("USB device not found.")
318318
if len(devices) > 1:
319-
logging.warning("Multiple devices found. Using the first one.")
319+
logger.warning("Multiple devices found. Using the first one.")
320320
self.dev = devices[0]
321321

322322
logger.info("Found USB device.")
@@ -357,7 +357,7 @@ async def stop(self):
357357

358358
if self.dev is None:
359359
raise ValueError("USB device was not connected.")
360-
logging.warning("Closing connection to USB device.")
360+
logger.warning("Closing connection to USB device.")
361361
usb.util.dispose_resources(self.dev)
362362
self.dev = None
363363

pylabrobot/resources/hamilton/hamilton_deck_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_summary(self):
7373
def test_assign_gigantic_resource(self):
7474
stanley_cup = StanleyCup_QUENCHER_FLOWSTATE_TUMBLER(name="HUGE")
7575
deck = STARLetDeck()
76-
with self.assertLogs() as log:
76+
with self.assertLogs("pylabrobot") as log:
7777
deck.assign_child_resource(stanley_cup, rails=1)
7878
self.assertEqual(
7979
log.output,

pylabrobot/storage/cytomat/cytomat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def _assemble_command(self, command_type: str, command: str, params: str):
9999

100100
async def send_command(self, command_type: str, command: str, params: str) -> str:
101101
async def _send_command(command_str) -> str:
102-
logging.debug(command_str.encode(self.serial_message_encoding))
102+
logger.debug(command_str.encode(self.serial_message_encoding))
103103
await self.io.write(command_str.encode(self.serial_message_encoding))
104104
resp = (await self.io.read(128)).decode(self.serial_message_encoding)
105105
if len(resp) == 0:
@@ -122,7 +122,7 @@ async def _send_command(command_str) -> str:
122122
await self.reset_error_register()
123123
raise Exception(f"Unknown cytomat error code in response: {resp}")
124124

125-
logging.error("Command %s received an unknown response: '%s'", command_str, resp)
125+
logger.error("Command %s received an unknown response: '%s'", command_str, resp)
126126
await self.reset_error_register()
127127
raise Exception(f"Unknown response from cytomat: {resp}")
128128

0 commit comments

Comments
 (0)