symfony/http-kernel · error · InvalidArgumentException
The log level " " does not exist.
Error message
The log level "%s" does not exist.
What it means
Symfony's monolog-free Log\Logger constructor validates that the given minimum level is a known PSR-3 level; if the string is not in its LEVELS map, it throws InvalidArgumentException immediately at construction time. This is fail-fast validation of a configuration value.
Solutions
- Use a valid PSR-3 LogLevel constant (e.g. LogLevel::WARNING)
- Fix typos such as 'warn' -> 'warning' and lowercase the value (strtolower)
- Sanitize env-derived levels before passing them to the constructor
- Catch InvalidArgumentException at boot to surface bad config early
Example fix
// before
new Logger('warn', $output);
// after
use Psr\Log\LogLevel;
new Logger(LogLevel::WARNING, $output); Defensive patterns
Strategy: validation
Validate before calling
$valid = ['debug','info','notice','warning','error','critical','alert','emergency'];
if (!in_array(strtolower($minLevel), $valid, true)) {
throw new \InvalidArgumentException("Invalid log level: $minLevel");
} Try / catch
try { $logger = new \Symfony\Component\HttpKernel\Log\Logger($minLevel, $output); } catch (\InvalidArgumentException $e) { /* fall back to default level */ $logger = new \Symfony\Component\HttpKernel\Log\Logger('error', $output); } Prevention
- Always use Psr\Log\LogLevel::* constants instead of raw strings
- Normalize env-derived levels with strtolower()
- Validate log config at deploy/bootstrap time
- Add a config schema test for log level values
When it happens
Trigger: Constructing Symfony\Component\HttpKernel\Log\Logger (or a service wired to it) with a $minLevel string that is not one of debug/info/notice/warning/error/critical/alert/emergency (or a valid verbosity constant mapping).
Common situations: Typo in a YAML/services log level config (e.g. 'warn' instead of 'warning'); uppercase levels like 'ERROR'; env var LOG_LEVEL containing an invalid value; custom factory passing verbosity strings directly.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Invalid log level " ".
- Unable to open " ".
- The "$tokens" argument of
- Message built by getControllerError(): e.g. Function
- Invalid dump format: " ".
AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13).
Data as JSON: /api/errors/69dd5822b96fec55.
Report an issue: GitHub.
Appendix: source
Thrown at Log/Logger.php:71
/** @var resource|null */
private $handle;
/**
* @param string|resource|null $output
*/
public function __construct(?string $minLevel = null, $output = null, ?callable $formatter = null, private readonly ?RequestStack $requestStack = null, bool $debug = false)
{
$minLevel ??= match ((int) ($_ENV['SHELL_VERBOSITY'] ?? $_SERVER['SHELL_VERBOSITY'] ?? 0)) {
-1 => LogLevel::ERROR,
1 => LogLevel::NOTICE,
2 => LogLevel::INFO,
3 => LogLevel::DEBUG,
default => null === $output || 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::ERROR : LogLevel::WARNING,
};
if (!isset(self::LEVELS[$minLevel])) {
throw new InvalidArgumentException(\sprintf('The log level "%s" does not exist.', $minLevel));
}
$this->minLevelIndex = self::LEVELS[$minLevel];
$this->formatter = null !== $formatter ? $formatter(...) : $this->format(...);
if ($output && false === $this->handle = \is_string($output) ? @fopen($output, 'a') : $output) {
throw new InvalidArgumentException(\sprintf('Unable to open "%s".', $output));
}
$this->debug = $debug;
}
public function enableDebug(): void
{
$this->debug = true;
}
public function log($level, $message, array $context = []): void
{
if (!isset(self::LEVELS[$level])) {View on GitHub (pinned to aa3a39d728)