{"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":"exception","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/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/logging.py#L625-L661","documentation":"Raised by `get_log_level_for_setting` when a configured logging level (e.g. `log_level`, `log_cli_level`) is a string that is neither a valid `logging` module constant (like \"INFO\") nor a parseable integer. pytest tries `int(getattr(logging, level, level))` and on ValueError raises UsageError suggesting to pass the numeric level instead.","triggerScenarios":"Setting `log_level = VERBOSE` or `log_cli_level = info-trace` in pytest.ini/pyproject.toml, or passing `--log-level=verbose` on the CLI. Also a bare string that is not an int and not a logging constant.","commonSituations":"Typos in level names. Using a custom logging level name defined at runtime that pytest cannot resolve at configure time. Copying a level name from another library (e.g. loguru) that isn't in stdlib logging.","solutions":["Use a standard logging level name: DEBUG, INFO, WARNING, ERROR, CRITICAL (case-insensitive).","Pass the numeric level instead, e.g. `--log-level=15` or `log_level = 15`.","Register custom level names via `logging.addLevelName(num, \"NAME\")` before pytest configures logging (in an early conftest/pytest_addoption)."],"exampleFix":"// before\n# pytest.ini\n[pytest]\nlog_level = VERBOSE\n// after\n[pytest]\nlog_level = DEBUG\n# or numeric: log_level = 10","handlingStrategy":"validation","validationCode":"import logging\n\ndef validate_log_level(level):\n    if isinstance(level, str):\n        level = level.upper()\n    val = getattr(logging, level, level) if isinstance(level, str) else level\n    try:\n        return int(val)\n    except (TypeError, ValueError):\n        raise ValueError(f\"{level!r} is not a valid logging level\")","typeGuard":"def is_valid_log_level(level) -> bool:\n    import logging\n    if isinstance(level, int):\n        return level > 0\n    if isinstance(level, str):\n        return hasattr(logging, level.upper()) or level.isdigit()\n    return False","tryCatchPattern":null,"preventionTips":["Use standard level names (DEBUG/INFO/WARNING/ERROR/CRITICAL) in config.","Pass numeric levels for custom levels.","Register custom level names via logging.addLevelName early."],"tags":["pytest","logging","config","usageerror"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}