Skip to content

Commit dcf122e

Browse files
committed
rework exception handling semantics
The choice is now whether to print a warning. Previously this was about re-raising the exception. This is done for stability's sake.
1 parent 6d865f1 commit dcf122e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

adafruit_logging.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def _level_for(value: int) -> str:
140140
- ``args`` - The additional positional arguments provided
141141
"""
142142

143-
raiseExceptions = False
143+
printHandlerExceptions = True
144+
"""
145+
Whether to print exceptions caught during handler's emit().
146+
"""
144147

145148

146149
def _logRecordFactory(name, level, msg, args):
@@ -343,11 +346,9 @@ def handle(self, record: LogRecord) -> None:
343346
try:
344347
handler.emit(record)
345348
except Exception as e: # pylint: disable=broad-except
346-
if raiseExceptions:
347-
raise e
348-
if sys.stderr:
349-
sys.stderr.write(f"Handler {handler} produced exception: "
350-
f"{repr(e)}\n")
349+
if sys.stderr and printHandlerExceptions:
350+
sys.stderr.write(f"Handler {repr(handler)} produced exception: "
351+
f"{str(e)}\n")
351352

352353
def log(self, level: int, msg: str, *args) -> None:
353354
"""Log a message.

0 commit comments

Comments
 (0)