WordPress/openverse-catalog

[Quality] Move logging.basicConfig calls out of import scope

AetherUnbound opened this issue · 0 comments

Current Situation

Currently, we have some provider API scripts that are calling logging.basicConfig at the top of the file, directly under imports.
By default, only the first call to logging.basicConfig is respected, subsequent calls are ignored.
Since these calls are happening at the global scope, they're likely being ignored (and particularly since Airflow sets its own config these get ignored anyway).

Suggested Improvement

I suggest we move the basicConfig info calls within the if __name__ == "__main__" block, and the setLevel calls within the provider script's main function.
This would ensure that the format is respected when running a provider with python /path/to/provider.py without causing redundant calls while importing.
Additionally, setLevel will be respected in both DAG & local run cases, without causing additional slowdowns during import.

Benefit

This reduces redundant calls and improves import speed/DAG parsing.

Additional context

Implementation

  • 🙋 I would be interested in implementing this feature.