setLogger example

if (empty(self::$logs[$key])) {
      self::$logs[$key] = new Log($key);

      // Every target already active for this connection key needs to have the       // logging object associated with it.       if (!empty(self::$connections[$key])) {
        foreach (self::$connections[$key] as $connection) {
          $connection->enableEvents([
            StatementExecutionStartEvent::class,
            StatementExecutionEndEvent::class,
          ]);
          $connection->setLogger(self::$logs[$key]);
        }
      }
    }

    self::$logs[$key]->start($logging_key);
    return self::$logs[$key];
  }

  /** * Retrieves the queries logged on for given logging key. * * This method also ends logging for the specified key. To get the query log * to date without ending the logger request the logging object by starting * it again (which does nothing to an open log key) and call methods on it as * desired. * * @param string $logging_key * The logging key to log. * @param string $key * The database connection key for which we want to log. * * @return array * The query log for the specified logging key and connection. * * @see \Drupal\Core\Database\Log */
$mpdfConfig = array_replace_recursive(
                $defaultConfig,
                [
                    'margin_left' => $this->_document['left'],
                    'margin_right' => $this->_document['right'],
                    'margin_top' => $this->_document['top'],
                    'margin_bottom' => $this->_document['bottom'],
                ]
            );
            if ($this->_preview == true || !$this->_documentHash) {
                $mpdf = new Mpdf($mpdfConfig);
                $mpdf->setLogger(
                    Shopware()->Container()->get('corelogger')
                );
                $mpdf->WriteHTML($html);
                $mpdf->Output();
                exit;
            }

            $tmpFile = tempnam(sys_get_temp_dir(), 'document');
            $mpdf = new Mpdf($mpdfConfig);
            $mpdf->setLogger(
                Shopware()->Container()->get('corelogger')
            );

    public function reset()
    {
        if ($this->client instanceof ResetInterface) {
            $this->client->reset();
        }
    }

    public function setLogger(LoggerInterface $logger): void
    {
        if ($this->client instanceof LoggerAwareInterface) {
            $this->client->setLogger($logger);
        }
    }

    public function withOptions(array $options)static
    {
        $clone = clone $this;
        $clone->client = $this->client->withOptions($options);

        return $clone;
    }
}
$dir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.mt_rand(111111, 999999);
        mkdir($dir, 0777, true);

        $loader = new ProjectTemplateCacheLoader($varLoader = new ProjectTemplateLoaderVar()$dir);
        $this->assertFalse($loader->load(new TemplateReference('foo', 'php')), '->load() returns false if the embed loader is not able to load the template');

        $logger = $this->createMock(LoggerInterface::class);
        $logger
            ->expects($this->once())
            ->method('debug')
            ->with('Storing template in cache.', ['name' => 'index']);
        $loader->setLogger($logger);
        $loader->load(new TemplateReference('index'));

        $logger = $this->createMock(LoggerInterface::class);
        $logger
            ->expects($this->once())
            ->method('debug')
            ->with('Fetching template from cache.', ['name' => 'index']);
        $loader->setLogger($logger);
        $loader->load(new TemplateReference('index'));
    }
}
$driver = $db->getPlatform();

            if ($driver === 'MySQLi') {
                $driverName = MySQLiHandler::class;
            } elseif ($driver === 'Postgre') {
                $driverName = PostgreHandler::class;
            }
        }

        $driver = new $driverName($config, AppServices::request()->getIPAddress());
        $driver->setLogger($logger);

        $session = new Session($driver$config);
        $session->setLogger($logger);

        if (session_status() === PHP_SESSION_NONE) {
            $session->start();
        }

        return $session;
    }

    
$this->assertFalse($loader->load(new TemplateReference('bar', 'php')), '->load() returns false if the template is not found');

        $storage = $loader->load(new TemplateReference('foo.php', 'php'));
        $this->assertInstanceOf(FileStorage::class$storage, '->load() returns a FileStorage if you pass a relative template that exists');
        $this->assertEquals($path.'/foo.php', (string) $storage, '->load() returns a FileStorage pointing to the absolute path of the template');

        $logger = $this->createMock(LoggerInterface::class);
        $logger->expects($this->exactly(2))->method('debug');

        $loader = new ProjectTemplateFilesystemLoader($pathPattern);
        $loader->setLogger($logger);
        $this->assertFalse($loader->load(new TemplateReference('foo.xml', 'php')), '->load() returns false if the template does not exist for the given engine');

        $loader = new ProjectTemplateFilesystemLoader([self::$fixturesPath.'/null/%name%', $pathPattern]);
        $loader->setLogger($logger);
        $loader->load(new TemplateReference('foo.php', 'php'));
    }
}


    public function testWithCliSapi()
    {
        try {
            // disable PHPUnit error handler to mimic a production environment             $isCalled = false;
            set_error_handler(function D) use (&$isCalled) {
                $isCalled = true;
            });
            $pool = new ApcuAdapter(str_replace('\\', '.', __CLASS__));
            $pool->setLogger(new NullLogger());

            $item = $pool->getItem('foo');
            $item->isHit();
            $pool->save($item->set('bar'));
            $this->assertFalse($isCalled);
        } finally {
            restore_error_handler();
        }
    }

    public function testCacheItemValueRunsThroughMarshaller()
    {


    /** * Returns the best possible adapter that your runtime supports. * * Using ApcuAdapter makes system caches compatible with read-only filesystems. */
    public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null): AdapterInterface
    {
        $opcache = new PhpFilesAdapter($namespace$defaultLifetime$directory, true);
        if (null !== $logger) {
            $opcache->setLogger($logger);
        }

        if (!self::$apcuSupported ??= ApcuAdapter::isSupported()) {
            return $opcache;
        }

        if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
            return $opcache;
        }

        $apcu = new ApcuAdapter($namespaceintdiv($defaultLifetime, 5)$version);
        
return $this->createSemaphoreFromKey(new Key($resource$limit$weight)$ttlInSecond$autoRelease);
    }

    /** * @param float|null $ttlInSecond Maximum expected semaphore duration in seconds * @param bool $autoRelease Whether to automatically release the semaphore or not when the semaphore instance is destroyed */
    public function createSemaphoreFromKey(Key $key, ?float $ttlInSecond = 300.0, bool $autoRelease = true): SemaphoreInterface
    {
        $semaphore = new Semaphore($key$this->store, $ttlInSecond$autoRelease);
        if ($this->logger) {
            $semaphore->setLogger($this->logger);
        }

        return $semaphore;
    }
}
public static function createClient(string $hosts, LoggerInterface $logger, bool $debug, array $sslConfig): Client
    {
        $hosts = array_filter(explode(',', $hosts));

        $clientBuilder = ClientBuilder::create();
        $clientBuilder->setHosts($hosts);

        if ($debug) {
            $clientBuilder->setTracer($logger);
        }

        $clientBuilder->setLogger($logger);

        if ($sslConfig['verify_server_cert'] === false) {
            $clientBuilder->setSSLVerification(false);
        }

        if (isset($sslConfig['cert_path'])) {
            $clientBuilder->setSSLCert($sslConfig['cert_path']$sslConfig['cert_password'] ?? null);
        }

        if (isset($sslConfig['cert_key_path'])) {
            $clientBuilder->setSSLKey($sslConfig['cert_key_path']$sslConfig['cert_key_password'] ?? null);
        }

        if ($this->client instanceof ResetInterface) {
            $this->client->reset();
        }

        $this->tracedRequests->exchangeArray([]);
    }

    public function setLogger(LoggerInterface $logger): void
    {
        if ($this->client instanceof LoggerAwareInterface) {
            $this->client->setLogger($logger);
        }
    }

    public function withOptions(array $options)static
    {
        $clone = clone $this;
        $clone->client = $this->client->withOptions($options);

        return $clone;
    }
}

                'client' => [
                    'curl' => [
                        CURLOPT_HTTPHEADER => [
                            'Content-type: application/json',
                        ],
                    ],
                ],
            ]
        );

        $clientBuilder->setLogger($eslogger);
        $clientBuilder->setTracer($eslogger);

        /** @var EsClientLogger $esClient */
        $esClient = $clientBuilder->build();

        $esClient->setLogger($eslogger);
        $esClient->setEvaluation($evaluationHelper);

        return $esClient;
    }
}
return $this->client->request($method$url$options);
    }

    public function stream(ResponseInterface|iterable $responses, float $timeout = null): ResponseStreamInterface
    {
        return $this->client->stream($responses$timeout);
    }

    public function setLogger(LoggerInterface $logger): void
    {
        if ($this->client instanceof LoggerAwareInterface) {
            $this->client->setLogger($logger);
        }
    }

    public function withOptions(array $options)static
    {
        $clone = clone $this;
        $clone->client = $this->client->withOptions($options);

        return $clone;
    }

    
class EarlyExpirationDispatcherTest extends TestCase
{
    public static function tearDownAfterClass(): void
    {
        (new Filesystem())->remove(sys_get_temp_dir().'/symfony-cache');
    }

    public function testFetch()
    {
        $logger = new TestLogger();
        $pool = new FilesystemAdapter();
        $pool->setLogger($logger);

        $item = $pool->getItem('foo');

        $computationService = new class() {
            public function __invoke(CacheItem $item)
            {
                return 123;
            }
        };

        $container = new Container();
        
use Symfony\Component\Templating\Tests\Fixtures\ProjectTemplateLoader;

/** * @group legacy */
class LoaderTest extends TestCase
{
    public function testGetSetLogger()
    {
        $loader = new ProjectTemplateLoader();
        $logger = $this->createMock(LoggerInterface::class);
        $loader->setLogger($logger);
        $this->assertSame($logger$loader->getLogger(), '->setLogger() sets the logger instance');
    }
}
Home | Imprint | This part of the site doesn't use cookies.