|
378 | 378 | ) |
379 | 379 | # --------------------------------------------------------------- |
380 | 380 |
|
381 | | -# Note: DEBUGGING is driven by the runtime config block, not a build-time |
382 | | -# constant, so logging is configured where DEBUGGING is enabled (below). |
| 381 | +# Note: DEBUGGING is driven by either the runtime config block, or a build-time |
| 382 | +# constant, so logging is configured lazily on first use in debug_print. |
| 383 | +_logging_configured = False |
383 | 384 |
|
384 | 385 | if has_windll: |
385 | 386 | class SYSTEM_INFO(ctypes.Structure): |
@@ -457,6 +458,14 @@ def crc16(data): |
457 | 458 | @export |
458 | 459 | def debug_print(msg): |
459 | 460 | if DEBUGGING: |
| 461 | + global _logging_configured |
| 462 | + if not _logging_configured: |
| 463 | + logging.basicConfig(level=logging.DEBUG) |
| 464 | + if DEBUGGING_LOG_FILE_PATH: |
| 465 | + file_handler = logging.FileHandler(DEBUGGING_LOG_FILE_PATH) |
| 466 | + file_handler.setLevel(logging.DEBUG) |
| 467 | + logging.getLogger().addHandler(file_handler) |
| 468 | + _logging_configured = True |
460 | 469 | logging.debug(msg) |
461 | 470 |
|
462 | 471 | def debug_hexdump(label, data): |
@@ -2298,11 +2307,6 @@ def encrypt(self, pt): |
2298 | 2307 | if config.get('debug_log'): |
2299 | 2308 | DEBUGGING = True |
2300 | 2309 | DEBUGGING_LOG_FILE_PATH = config['debug_log'] |
2301 | | - logging.basicConfig(level=logging.DEBUG) |
2302 | | - if DEBUGGING_LOG_FILE_PATH: |
2303 | | - _dbg_fh = logging.FileHandler(DEBUGGING_LOG_FILE_PATH) |
2304 | | - _dbg_fh.setLevel(logging.DEBUG) |
2305 | | - logging.getLogger().addHandler(_dbg_fh) |
2306 | 2310 | transport = config['transports'][0] |
2307 | 2311 | # PATCH-SETUP-STAGELESS-TCP-SOCKET # |
2308 | 2312 | # For staged/stageless TCP payloads where the socket `s` is already |
|
0 commit comments