{"record":{"id":"afdd1a4b5b60ffa8","repo":"pytest-dev/pytest","slug":"log-level-is-not-recognized-as-a-logging-level","errorCode":null,"errorMessage":"'{log_level}' is not recognized as a logging level name for '{setting_name}'. Please consider passing the logging level num instead.","messagePattern":"'(.+?)' is not recognized as a logging level name for '(.+?)'\\. Please consider passing the logging level num instead\\.","errorType":"validation","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/logging.py","lineNumber":643,"sourceCode":"\n\ndef get_log_level_for_setting(config: Config, *setting_names: str) -> int | None:\n    for setting_name in setting_names:\n        log_level = config.getoption(setting_name)\n        if log_level is None:\n            log_level = config.getini(setting_name)\n        if log_level:\n            break\n    else:\n        return None\n\n    if isinstance(log_level, str):\n        log_level = log_level.upper()\n    try:\n        return int(getattr(logging, log_level, log_level))\n    except ValueError as e:\n        # Python logging does not recognise this as a logging level\n        raise UsageError(\n            f\"'{log_level}' is not recognized as a logging level name for \"\n            f\"'{setting_name}'. Please consider passing the \"\n            \"logging level num instead.\"\n        ) from e\n\n\n# run after terminalreporter/capturemanager are configured\n@hookimpl(trylast=True)\ndef pytest_configure(config: Config) -> None:\n    config.pluginmanager.register(LoggingPlugin(config), \"logging-plugin\")\n\n\nclass LoggingPlugin:\n    \"\"\"Attaches to the logging module and captures log messages for each test.\"\"\"\n\n    def __init__(self, config: Config) -> None:\n        \"\"\"Create a new plugin to capture log messages.\n","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/logging.py#L625-L661","documentation":"logging.py:643 raises UsageError when the configured log_level (from log_level or log_cli_level ini options) is a string that is neither a numeric nor a recognized logging level name (CRITICAL/ERROR/WARNING/INFO/DEBUG/NOTSET). The code tries int(getattr(logging, log_level, log_level)); if that raises ValueError, the name is invalid.","triggerScenarios":"Setting log_level = VERBOSE or log_cli_level = info_t in pytest.ini / pyproject.toml / CLI --log-level; typo in a level name; passing a level that is a custom int but as an invalid string.","commonSituations":"Typos like 'warnging'; using framework-specific level names (e.g. 'VERBOSE' from a third-party logger) that are not on the standard logging module; copy-pasting level names with trailing whitespace.","solutions":["Use a standard level name: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET (case-insensitive).","Pass a numeric level (e.g. --log-level=15) if you need a custom verbosity.","Check for stray whitespace/typos in the ini value."],"exampleFix":"// before\n# pytest.ini\nlog_level = verbose\n// after\nlog_level = DEBUG","handlingStrategy":"validation","validationCode":"import logging\nVALID = {'CRITICAL','ERROR','WARNING','INFO','DEBUG','NOTSET'}\ndef validate_level(level: str) -> str:\n    if not (level.upper() in VALID or level.isdigit()):\n        raise ValueError(f'invalid log level {level!r}; use {VALID} or an int')\n    return level","typeGuard":"def is_valid_log_level(v) -> bool:\n    return isinstance(v, int) or (isinstance(v, str) and (v.upper() in {'CRITICAL','ERROR','WARNING','INFO','DEBUG','NOTSET'} or v.isdigit()))","tryCatchPattern":null,"preventionTips":["Use standard logging level names in ini files.","Use numeric levels for custom verbosity.","Validate config-driven level names at startup."],"tags":["pytest","logging","config","ini","validation"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}