{"record":{"id":"78ea15b1f2f4a634","repo":"agentscope-ai/agentscope","slug":"invalid-logging-level-level-must-be-one-of-in","errorCode":null,"errorMessage":"Invalid logging level: {level}. Must be one of 'INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL'.","messagePattern":"Invalid logging level: (.+?)\\. Must be one of 'INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/_logging.py","lineNumber":29,"sourceCode":"\nlogger = logging.getLogger(\"as\")\n\n\ndef setup_logger(\n    level: str,\n    filepath: str | None = None,\n) -> None:\n    \"\"\"Set up the agentscope logger.\n\n    Args:\n        level (`str`):\n            The logging level, chosen from \"INFO\", \"DEBUG\", \"WARNING\",\n            \"ERROR\", \"CRITICAL\".\n        filepath (`str | None`, optional):\n            The filepath to save the logging output.\n    \"\"\"\n    if level not in [\"INFO\", \"DEBUG\", \"WARNING\", \"ERROR\", \"CRITICAL\"]:\n        raise ValueError(\n            f\"Invalid logging level: {level}. Must be one of \"\n            f\"'INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL'.\",\n        )\n    logger.handlers.clear()\n    logger.setLevel(level)\n    handler = logging.StreamHandler()\n    handler.setFormatter(logging.Formatter(_DEFAULT_FORMAT))\n    logger.addHandler(handler)\n\n    if filepath:\n        handler = logging.FileHandler(filepath)\n        handler.setFormatter(logging.Formatter(_DEFAULT_FORMAT))\n        logger.addHandler(handler)\n\n    logger.propagate = False\n\n\nsetup_logger(\"INFO\")","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/_logging.py#L11-L47","documentation":"This error is raised by agentscope's setup_logger when the `level` argument is not one of the five allowed logging level strings. The library validates eagerly because Python's logging module accepts other values (e.g. numeric levels or 'WARN') that agentscope does not want to support. Passing anything else aborts logger configuration.","triggerScenarios":"Calling setup_logger(level=...) with a non-uppercase string ('info', 'warn'), a numeric level (logging.DEBUG = 10), 'WARN' (not in the list), or None.","commonSituations":"Copy-pasting logging constants from stdlib logging (logging.INFO), using lowercase level strings from env vars like LOG_LEVEL=debug without .upper(), or using 'WARN' which stdlib allows but agentscope rejects.","solutions":["Pass an exact uppercase string: 'INFO', 'DEBUG', 'WARNING', 'ERROR', or 'CRITICAL'","If the level comes from config/env, normalize it first: level = os.environ['LOG_LEVEL'].upper() and validate against the allowed list","Do not pass logging module constants (e.g. logging.DEBUG); use the string form"],"exampleFix":"// before\nsetup_logger(level=logging.DEBUG)  # or level=\"debug\"\n\n# after\nsetup_logger(level=\"DEBUG\")","handlingStrategy":"validation","validationCode":"VALID_LEVELS = {\"INFO\", \"DEBUG\", \"WARNING\", \"ERROR\", \"CRITICAL\"}\nlevel = os.environ.get(\"LOG_LEVEL\", \"INFO\").upper()\nif level not in VALID_LEVELS:\n    raise ValueError(f\"Unsupported LOG_LEVEL {level!r}; choose from {sorted(VALID_LEVELS)}\")\nsetup_logger(level=level)","typeGuard":"from typing import Literal\nLogLevel = Literal[\"INFO\", \"DEBUG\", \"WARNING\", \"ERROR\", \"CRITICAL\"]\n\ndef is_log_level(v: str) -> TypeGuard[LogLevel]:\n    return v in {\"INFO\", \"DEBUG\", \"WARNING\", \"ERROR\", \"CRITICAL\"}","tryCatchPattern":null,"preventionTips":["Normalize incoming level strings with .upper() and strip whitespace before passing","Never pass logging module constants; use the literal string forms","Validate level against the allowed set in config loading, near the source of user input"],"tags":["logging","configuration","validation","python"],"backgroundTag":"invalid-argument-value","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}