Skip to content

Commit e7a8fc1

Browse files
myfjinclaude
andcommitted
Sync 6 patterns to canonical: move logging.basicConfig() into __main__
async_task_queue, connection_pool_health_checks, dead_letter_queue, event_bus, http_retry_client, saga_coordinator — each had logging.basicConfig() at module scope, which silently reconfigures the root logger for anything that imports it. Moved into the __main__ block with a NOTE explaining why, matching the canonical signed-library version. 99/99 patterns now byte-identical (sig-stripped) with python/programming. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent c024dc9 commit e7a8fc1

6 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎patterns/architecture/event_bus.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from datetime import datetime
2929

3030
# Configure logging
31-
logging.basicConfig(level=logging.INFO)
3231
logger = logging.getLogger(__name__)
3332

3433
# Type variables for generic typing
@@ -244,4 +243,8 @@ async def produce(channel, payloads):
244243

245244

246245
if __name__ == "__main__":
246+
# NOTE: logging.basicConfig() configures the ROOT logger, which belongs to the
247+
# application, not to a library. Calling it at import time silently reconfigures
248+
# logging for anything that imports this pattern, so it lives under __main__.
249+
logging.basicConfig(level=logging.INFO)
247250
asyncio.run(main())

‎patterns/architecture/saga_coordinator.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import logging
1515

1616
# Configure logging
17-
logging.basicConfig(level=logging.INFO)
1817
logger = logging.getLogger(__name__)
1918

2019

@@ -302,4 +301,8 @@ def bad_undo(context):
302301

303302

304303
if __name__ == "__main__":
304+
# NOTE: logging.basicConfig() configures the ROOT logger, which belongs to the
305+
# application, not to a library. Calling it at import time silently reconfigures
306+
# logging for anything that imports this pattern, so it lives under __main__.
307+
logging.basicConfig(level=logging.INFO)
305308
main()

‎patterns/async/async_task_queue.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from collections import defaultdict
2121

2222
# Configure logging
23-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
2423
logger = logging.getLogger(__name__)
2524

2625

@@ -386,4 +385,8 @@ async def main() -> None:
386385

387386

388387
if __name__ == "__main__":
388+
# NOTE: logging.basicConfig() configures the ROOT logger, which belongs to the
389+
# application, not to a library. Calling it at import time silently reconfigures
390+
# logging for anything that imports this pattern, so it lives under __main__.
391+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
389392
asyncio.run(main())

‎patterns/networking/connection_pool_health_checks.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from contextlib import contextmanager
1818

1919
# Configure logging
20-
logging.basicConfig(level=logging.INFO)
2120
logger = logging.getLogger(__name__)
2221

2322

@@ -407,4 +406,8 @@ def worker(worker_id: int) -> None:
407406

408407

409408
if __name__ == "__main__":
409+
# NOTE: logging.basicConfig() configures the ROOT logger, which belongs to the
410+
# application, not to a library. Calling it at import time silently reconfigures
411+
# logging for anything that imports this pattern, so it lives under __main__.
412+
logging.basicConfig(level=logging.INFO)
410413
main()

‎patterns/networking/http_retry_client.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import json
2121

2222
# Configure logging
23-
logging.basicConfig(level=logging.INFO)
2423
logger = logging.getLogger(__name__)
2524

2625

@@ -487,4 +486,8 @@ def log_message(self, *args):
487486

488487

489488
if __name__ == "__main__":
489+
# NOTE: logging.basicConfig() configures the ROOT logger, which belongs to the
490+
# application, not to a library. Calling it at import time silently reconfigures
491+
# logging for anything that imports this pattern, so it lives under __main__.
492+
logging.basicConfig(level=logging.INFO)
490493
main()

‎patterns/resilience/dead_letter_queue.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import logging
1818

1919
# Configure logging
20-
logging.basicConfig(level=logging.INFO)
2120
logger = logging.getLogger(__name__)
2221

2322

@@ -375,4 +374,8 @@ def processor(message: DLQMessage) -> bool:
375374

376375

377376
if __name__ == "__main__":
377+
# NOTE: logging.basicConfig() configures the ROOT logger, which belongs to the
378+
# application, not to a library. Calling it at import time silently reconfigures
379+
# logging for anything that imports this pattern, so it lives under __main__.
380+
logging.basicConfig(level=logging.INFO)
378381
main()

0 commit comments

Comments
 (0)