Revision: Tue, 16 Aug 2022 19:49:12 GMT

Profiling and Logging

Cycle Database does not provide logging abilities on the core level, however, it provides multiple points at which logger can be integrated.

Both DatabaseManager and each of the database drivers implements the Psr\Log\LoggerAwareInterface and you can enable SQL logging by assigning a logger:

Globally for each driver

$dbal = new DatabaseManager(
    new DatabaseConfig(...)


For specific driver

$driver = $dbal->database('default')->getDriver();

Globally via Logger factory

use Cycle\Database\DatabaseManager;
use Cycle\Database\Config\DatabaseConfig;
use Cycle\Database\LoggerFactoryInterface;

class CustomLoggerFactory implements LoggerFactoryInterface {

    public function getLogger(DriverInterface $driver = null): LoggerInterface
        if ($driver->getType() === 'SQLite') {
            return new FileLooger();
        return new \Psr\Log\NullLogger();

$dbal = new DatabaseManager(
    new DatabaseConfig(...), 
    new CustomLoggerFactory()
Edit this page