symfony/monolog-bundle
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
monolog/monolog | 3.6.0 | - | MIT | prod | |
symfony/config | v7.0.7 | - | MIT | prod dev | |
symfony/dependency-injection | v7.0.7 | - | MIT | prod dev | |
symfony/http-kernel | v7.0.7 | - | MIT | prod dev | |
symfony/monolog-bridge | v7.0.7 | - | MIT | prod |
The symfony/monolog-bundle is an integral package in Symfony that facilitates the utilization of the Monolog library. Monolog is a PHP-based logging library, and this bundle's function is to integrate it smoothly into the Symfony framework. That can significantly enhance your ability to log messages, errors, or even structured data, providing you with necessary insights and helping debug your application easily and effectively.
To use the symfony/monolog-bundle in your project, you need to follow these steps.
composer require symfony/monolog-bundle
# config/packages/monolog.yaml
monolog:
channels: ["my_channel"]
handlers:
my_handler:
type: stream
path: "%kernel.logs_dir%/my_channel.log"
level: debug
channels: ["my_channel"]
Please note that in this example, a new log channel named 'my_channel' is being generated. It is configured to use a handler 'my_handler' that logs the messages into a file my_channel.log and the log level specified is 'debug'.
<?php
namespace App\Controller;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends AbstractController
{
public function index(LoggerInterface $myChannelLogger): Response
{
$myChannelLogger->info('I just logged in!');
return $this->render('default/index.html.twig');
}
}
Here, 'myChannelLogger' is our custom log channel injected into the 'index' action of 'DefaultController'. And we're logging an info message saying 'I just logged in!'.
Please keep in mind that these are basic usage examples. It's possible to utilize different channels, handlers, and log levels for a more complex setup.
The primary source for the symfony/monolog-bundle's documentation is found on the official Symfony website. You can access detailed information about its usage, configuration, and features from Symfony Documentation. Additionally, for more information about Monolog itself and its capabilities, visiting the Monolog GitHub repository would be beneficial.