New in Symfony 3.4: Minimalist PSR-3 logger
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Symfony Flex proposes a whole new philosophy when developing Symfony 3.3 or newer applications. The main difference with respect to the old Symfony Standard Edition is that applications now must explicitly install everything they need, instead of having to remove what they don't need.
In practice, this means that you need to install the console recipe (
composer require cli)
before running any command, the Twig recipe (
composer require twig) before
rendering a single template, etc. This also means that you don't have a logger
unless you install Monolog via the logging recipe (
composer require log).
However, given that logging is essential for all applications, in Symfony 3.4 we introduced a new and minimalist PSR-3 based logger which is always available in all Symfony applications without having to install any package.
The new logger is available as the
logger service and, if you use autowiring,
via the injection of
Psr\Log\LoggerInterface. The logger has been designed
to integrate seamlessly with containerization (Docker) and orchestration (Kubernetes)
tools, as well as with most modern cloud providers. When using those, logs will
be automatically collected, aggregated and stored. In addition:
- It writes contents by default to
- It defines the same seven log levels as Monolog, but it only logs warning messages or higher by default;
- It defines a simple method to log messages:
log($level, $message, array $context = )(where
Psr\Log\LogLevel::INFO, etc.) and the traditional shortcut methods (
- Log messages are displayed in the console when running the integrated PHP web
bin/console server:startor Flex's
This new logger is minimalist by nature and it can be considered "feature complete". We'll never add more features or methods or configuration options to it. If you need more options and features, you must use Monolog instead.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.