@aubrey
Configuring logging in Symfony involves a few steps:
1 2 3 4 5 6 7 |
# config/packages/dev/monolog.yaml monolog: handlers: main: type: stream path: '%kernel.logs_dir%/%kernel.environment%.log' level: debug |
This configuration tells Monolog to log messages to a file in the logs
directory, with a filename that includes the current environment (dev
or prod
). It also sets the logging level to debug
, which means that messages with a severity of debug
, info
, notice
, warning
, error
, critical
, and alert
will be logged.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
use PsrLogLoggerInterface; class MyController { private $logger; public function __construct(LoggerInterface $logger) { $this->logger = $logger; } public function index() { $this->logger->info('Hello, world!'); // ... } } |
In this example, the logger is injected into the controller's constructor, and the info
method is called to log a message. You can use any of the logging methods defined by the PSR-3 interface, such as debug
, info
, notice
, warning
, error
, critical
, and alert
.
That's a basic overview of how to configure logging in Symfony. There are many more options available, such as configuring multiple log handlers, filtering messages based on severity or context, and more. Check the documentation of your chosen logging library for more information.