{"record":{"id":"c04f5d9be6fd8b5c","repo":"symfony/http-kernel","slug":"invalid-log-level-s","errorCode":null,"errorMessage":"Invalid log level \"%s\".","messagePattern":"Invalid log level \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Attribute/WithLogLevel.php","lineNumber":30,"sourceCode":"namespace Symfony\\Component\\HttpKernel\\Attribute;\n\nuse Psr\\Log\\LogLevel;\n\n/**\n * Defines the log level applied to an exception.\n *\n * @author Dejan Angelov <angelovdejan@protonmail.com>\n */\n#[\\Attribute(\\Attribute::TARGET_CLASS)]\nfinal class WithLogLevel\n{\n    /**\n     * @param LogLevel::* $level The level to use to log the exception\n     */\n    public function __construct(public readonly string $level)\n    {\n        if (!\\defined('Psr\\Log\\LogLevel::'.strtoupper($this->level))) {\n            throw new \\InvalidArgumentException(\\sprintf('Invalid log level \"%s\".', $this->level));\n        }\n    }\n}\n","sourceCodeStart":12,"sourceCodeEnd":34,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Attribute/WithLogLevel.php#L12-L34","documentation":"The #[WithLogLevel] attribute restricts its level parameter to valid PSR-3 LogLevel constants, checked at construction by testing that Psr\\Log\\LogLevel::<UPPERCASED> is defined. Any other string throws InvalidArgumentException at attribute-resolution time.","triggerScenarios":"Declaring #[WithLogLevel('warn')], uppercase/misspelled levels ('ERROR', 'verbose'), or any string that is not debug/info/notice/warning/error/critical/alert/emergency on an exception class or method.","commonSituations":"Typos in exception logging attributes; using a library-specific level name that isn't PSR-3; config-driven level strings interpolated into the attribute; upgrading code from a logger with non-PSR levels.","solutions":["Use a valid PSR-3 level string: 'debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'","Fix case: use lowercase 'warning', not 'WARNING' or 'WARN'","Check defined('Psr\\Log\\LogLevel::'.strtoupper($level)) before wiring dynamic levels","Reference LogLevel:: class constants to get IDE validation"],"exampleFix":"// before\n#[WithLogLevel('warn')]\nclass MyException extends \\RuntimeException {}\n\n// after\n#[WithLogLevel('warning')]\nclass MyException extends \\RuntimeException {}","handlingStrategy":"validation","validationCode":"const LEVELS = ['debug','info','notice','warning','error','critical','alert','emergency'];\nif (!LEVELS.includes(level)) throw new Error(`Invalid log level: ${level}`);","typeGuard":"function isLogLevel(string $level): bool {\n  return \\defined('Psr\\Log\\LogLevel::'.strtoupper($level));\n}","tryCatchPattern":"try { $attr = new \\Symfony\\Component\\HttpKernel\\Attribute\\WithLogLevel($level); } catch (\\InvalidArgumentException $e) { $attr = new \\Symfony\\Component\\HttpKernel\\Attribute\\WithLogLevel('critical'); }","preventionTips":["Use lowercase PSR-3 level names ('warning', not 'WARN')","Reference LogLevel::* constants to get IDE/static validation","Validate config-driven levels against the PSR-3 list at boot","Add a test that reflects all #[WithLogLevel] usages in the codebase"],"tags":["attributes","logging","psr-3","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}