Commit 2261661
authored
Replace traceback.print_exc() with logger.exception() for proper logging (#160)
Using traceback.print_exc() and traceback.print_exception() writes directly
to stderr, bypassing the Python logging system. This prevents users from:
- Configuring log destinations (files, syslog, cloud services)
- Controlling log levels and filtering
- Using structured logging formats (JSON, etc.)
- Integrating with monitoring and alerting systems
PEP 337 explicitly recommends: "Replace traceback.print_exception with
_log.exception" and states that modules should "use the logging system
instead of print or sys.stdout.write."
Changes:
- Added logging.getLogger(__name__) to server.py and server_context.py
- Replaced traceback.print_exc() with logger.exception() in 2 locations
- Replaced traceback.print_exception() with logger.exception() in 2 locations
This allows applications using the SDK to properly control exception logging
through standard Python logging configuration.
References:
- PEP 337: https://peps.python.org/pep-0337/
- Python Logging HOWTO: https://docs.python.org/3/howto/logging.html1 parent 292a6ef commit 2261661
2 files changed
+9
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | | - | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
165 | 167 | | |
166 | 168 | | |
167 | 169 | | |
168 | | - | |
| 170 | + | |
169 | 171 | | |
170 | 172 | | |
171 | 173 | | |
| |||
272 | 274 | | |
273 | 275 | | |
274 | 276 | | |
275 | | - | |
| 277 | + | |
276 | 278 | | |
277 | 279 | | |
278 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
448 | 450 | | |
449 | 451 | | |
450 | 452 | | |
451 | | - | |
452 | | - | |
| 453 | + | |
453 | 454 | | |
454 | 455 | | |
455 | 456 | | |
| |||
469 | 470 | | |
470 | 471 | | |
471 | 472 | | |
472 | | - | |
473 | | - | |
| 473 | + | |
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
| |||
0 commit comments