PHP code example of harmonicdigital / doctrine-dbal-logger
1. Go to this page and download the library: Download harmonicdigital/doctrine-dbal-logger library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
harmonicdigital / doctrine-dbal-logger example snippets
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use HarmonicDigital\DoctrineDbal\Logging\Middleware;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// Create your PSR-3 logger
$logger = new Logger('doctrine');
$logger->pushHandler(new StreamHandler('doctrine.log', Logger::DEBUG));
// Create the middleware
$middleware = new Middleware($logger);
// Configure DBAL with the middleware
$configuration = new Configuration();
$configuration->setMiddlewares([$middleware]);
// Create your connection
$connection = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'path' => ':memory:',
], $configuration);
use HarmonicDigital\DoctrineDbal\Logging\DoctrineLogger;
use HarmonicDigital\DoctrineDbal\Logging\DoctrineLoggerInterface;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// Create your PSR-3 logger
$logger = new Logger('doctrine');
$logger->pushHandler(new StreamHandler('doctrine.log', Logger::DEBUG));
$middleware = new Middleware(new DoctrineLogger(
$logger,
[
// Overriding log levels
DoctrineLoggerInterface::LOG_CONNECT => Logger::DEBUG,
DoctrineLoggerInterface::LOG_ROLL_BACK => Logger::WARNING,
],
[
// Overriding log messages
DoctrineLoggerInterface::LOG_ROLL_BACK => 'Rolling back transaction',
],
));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.