Skip to content

Replace application prints and bare excepts with logging - #593

Merged
jrhoads merged 1 commit into
devfrom
quickwin/logging
Sep 30, 2026
Merged

jrhoads merged 1 commit into
devfrom
quickwin/logging

Conversation

@jrhoads

@jrhoads jrhoads commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Purpose

Send application trace output through the logging system, and stop bare except clauses from swallowing SystemExit and KeyboardInterrupt.

Approach

Replace print() in application modules with logging.getLogger(__name__). Leave test progress output as print(). Replace the bare except: clauses in getrordump.py and create_update.py with except Exception. Add a console handler for the rorapi logger at INFO so those messages still show up the way the prints did.

Key Modifications

  • Log former print() calls in views, CSV create/update/bulk helpers, record validation, setup, and record create/update.
  • Log the missing DATA_STORE notice with logger.warning.
  • Catch Exception instead of a bare except when reading a GitHub dump response, saving the dump zip, and looking up a Geonames id.
  • Configure the rorapi logger to write INFO messages to the console.

Important Technical Details

  • except Exception does not catch SystemExit. The dump zip check that raises SystemExit when the archive contains an extra directory now reaches the caller instead of being replaced with "Something went wrong saving zip file".
  • Test files still use print() for progress and score output.
  • A commented-out print in es_utils.py is unchanged.
  • Default Django logging does not show INFO logs from app loggers. The new LOGGING entry does, without changing the django logger.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Test plan

  • CI tests_unit on this PR

Reviewer, please remember our guidelines:

  • Be humble in the language and feedback you give, ask don't tell.
  • Consider using positive language as opposed to neutral when offering feedback. This is to avoid the negative bias that can occur with neutral language appearing negative.
  • Offer suggestions on how to improve code e.g. simplification or expanding clarity.
  • Ensure you give reasons for the changes you are proposing.
Open in Web Open in Cursor 

Application print calls now go through logging.getLogger(__name__). Bare excepts in the dump download and Geonames update catch Exception, so SystemExit and KeyboardInterrupt are not swallowed.

Co-authored-by: Joseph Rhoads <jrhoads@users.noreply.github.com>
@cursor
cursor Bot force-pushed the quickwin/logging branch from 4e4ce2a to c1df708 Compare September 30, 2026 15:55
@jrhoads
jrhoads merged commit bea1029 into dev Sep 30, 2026
2 of 3 checks passed
@jrhoads
jrhoads deleted the quickwin/logging branch September 30, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants