Four scripts (one of which is a legacy script) and the aphis lib had instances of using print or sys.stderr or sys.stdout that have been converted to use the logging module
There is one instance of sys.stdout usage in 03-parse-inspection-pdfs.py in the case where the script is run with the test command-line argument (Test parsing against a single PDF, writing results to stdout.) that was left as is.
I decided to customize the format string for the log handler (instead of calling basicConfig without any args) so that the filename of the script that generated the log and line number of log location are prefixed in the log message. Without it, the log messages are without context, always prefixed with 'main' regardless of script name (which felt a bit unhelpful) since each script is run individually by your make or scrape workflow.
Limitation: If code within lib/aphis.py needs its logs to be formatted differently from the scripts that import the library, the log formatting selected in lib/aphis.pywill override any basic config that the scripts that import lib/aphis.py attempt. There's a way to avoid this that I can get into more detail in this pull request's discussion if you'd like to dig deeper. But it felt like overkill for this set of scripts and library.
Testing
Ran the individual scripts via the make commands to ensure nothing was broken and that the log messages were appearing on the console as expected. Ran the script that does the upload to DocumentCloud in a slightly modified execution path that would allow me to test the logging without inadvertently uploading something to DocumentCloud
Details
print
orsys.stderr
orsys.stdout
that have been converted to use the logging modulesys.stdout
usage in03-parse-inspection-pdfs.py
in the case where the script is run with thetest
command-line argument (Test parsing against a single PDF, writing results to stdout.) that was left as is.basicConfig
without any args) so that the filename of the script that generated the log and line number of log location are prefixed in the log message. Without it, the log messages are without context, always prefixed with 'main' regardless of script name (which felt a bit unhelpful) since each script is run individually by yourmake
orscrape
workflow.lib/aphis.py
needs its logs to be formatted differently from the scripts that import the library, the log formatting selected inlib/aphis.py
will override any basic config that the scripts that importlib/aphis.py
attempt. There's a way to avoid this that I can get into more detail in this pull request's discussion if you'd like to dig deeper. But it felt like overkill for this set of scripts and library.Testing
Ran the individual scripts via the make commands to ensure nothing was broken and that the log messages were appearing on the console as expected. Ran the script that does the upload to DocumentCloud in a slightly modified execution path that would allow me to test the logging without inadvertently uploading something to DocumentCloud