Description
While reading through the codebase I noticed that preprocess-modsec-log.py has a bug in how it calls the logger.
On line 117, log.error("Error writing to file", e) passes the exception as a positional argument but there is no %s in the format string. Python's logging module tries to format it as msg % args internally which raises a TypeError. So when a file write actually fails, the error is never logged you just get a --- Logging error --- traceback on stderr and the failure goes unnoticed. The same pattern exists on lines 95, 97, 101, 102 with log.debug() calls.
Reproduce
import logging
logging.basicConfig(level=logging.ERROR)
log = logging.getLogger('test')
log.error("Error writing to file", Exception("disk full"))
Fix
log.error("Error writing to file: %s", e) # line 117
log.debug("Processed file lines: %s", procIndex) # line 95
log.debug("Original file lines: %s", origIndex) # line 97
log.debug("Head: %s", index) # line 101
log.debug("Write Mode: %s", writeMode) # line 102
Description
While reading through the codebase I noticed that preprocess-modsec-log.py has a bug in how it calls the logger.
On line 117, log.error("Error writing to file", e) passes the exception as a positional argument but there is no %s in the format string. Python's logging module tries to format it as msg % args internally which raises a TypeError. So when a file write actually fails, the error is never logged you just get a --- Logging error --- traceback on stderr and the failure goes unnoticed. The same pattern exists on lines 95, 97, 101, 102 with log.debug() calls.
Reproduce
import logging
logging.basicConfig(level=logging.ERROR)
log = logging.getLogger('test')
log.error("Error writing to file", Exception("disk full"))
Fix
log.error("Error writing to file: %s", e) # line 117
log.debug("Processed file lines: %s", procIndex) # line 95
log.debug("Original file lines: %s", origIndex) # line 97
log.debug("Head: %s", index) # line 101
log.debug("Write Mode: %s", writeMode) # line 102