Repository navigation
fix(utils): fall back to INFO for a blank or unknown LOG_LEVEL - #10245
Merged
tastelikefeet merged 2 commits intoSep 26, 2026
Merged
tastelikefeet merged 2 commits into
tastelikefeet merged 2 commits into
Conversation
LOG_LEVEL was read twice with different tolerance: get_logger() used getattr(logging, value, logging.INFO) while the module-level ms_logger.setLevel(value) passed the raw string, so `LOG_LEVEL=` made every import of swift.utils raise ValueError before a run could start.
tastelikefeet
approved these changes
Sep 26, 2026
1 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
LOG_LEVELis read twice inswift/utils/logger.py, and the two read sites disagree about what to do with a value that is not a level name.get_logger()normalises it withgetattr(logging, log_level, logging.INFO), so an unusable value falls back toINFO.ms_logger.setLevel(log_level), andLogger.setLevel()raises for anything that is not a level name.So the tolerant path is the one that never gets to run:
An empty
LOG_LEVELis easy to get by accident —ENV LOG_LEVEL=in a Dockerfile,LOG_LEVEL=in a launcher script or.env, or a variable that a scheduler still exports while empty. In that state every module that imports the logger fails, so the job dies at import time over a cosmetic setting, and the same happens for a value padded with blanks or misspelled. The documented contract is only "LOG_LEVEL: The log level, default is 'INFO'. You can set it to 'WARNING', 'ERROR', etc." — nothing promises an exception, andget_logger()already treats a bad value asINFO.What changed
Both read sites now share one
_get_log_level()helper that strips the value, upper-cases it and always returns a numeric level. Valid settings keep working exactly as before, including the spellings that already worked:LOG_LEVELINFOINFOWARNINGWARNINGWARNINGwarningWARNINGWARNING''INFO' 'INFOVERBOSEINFOHow it was checked
tests/utils/test_log_level.pyresolves both loggers in a fresh interpreter, because the failure happens at import time and cannot be reproduced in-process. Run with the same runner CI uses:Ran 6 tests ... FAILED (failures=3)— the blank, the whitespace-padded and the unknown value, with the traceback above;Ran 6 tests ... OK, including the two controls that pinWARNING/warningto level 30 and unset to 20.pre-commit run --files swift/utils/logger.py tests/utils/test_log_level.pypasses (flake8, isort, yapf and the formatting hooks). The rest oftests/utilsis unaffected: in my environment it reportserrors=38, skipped=22both with and without this patch — those errors are optional dependencies missing locally (e.g.pydantic), not this change.No linked issue.
Disclosure: this PR was prepared, tested and submitted by an AI agent working on behalf of the account owner.