public function testCanSetTemplate() { $l = new BackoffLogger(new ClosureLogAdapter(function () { })); $l->setTemplate('foo'); $t = $this->readAttribute($l, 'formatter'); $this->assertEquals('foo', $this->readAttribute($t, 'template')); }
/** * Add backoff logging to the backoff plugin if needed * * @param BackoffPlugin $plugin Backoff plugin * @param Collection $config Configuration settings * * @throws InvalidArgumentException */ protected function addBackoffLogger(BackoffPlugin $plugin, Collection $config) { // The log option can be set to `debug` or an instance of a LogAdapterInterface if ($logger = $config->get(Options::BACKOFF_LOGGER)) { $format = $config->get(Options::BACKOFF_LOGGER_TEMPLATE); if ($logger === 'debug') { $logger = new ClosureLogAdapter(function ($message) { trigger_error($message . "\n"); }); } elseif (!$logger instanceof LogAdapterInterface) { throw new InvalidArgumentException(Options::BACKOFF_LOGGER . ' must be set to `debug` or an instance of ' . 'Guzzle\\Common\\Log\\LogAdapterInterface'); } // Create the plugin responsible for logging exponential backoff retries $logPlugin = new BackoffLogger($logger); // You can specify a custom format or use the default if ($format) { $logPlugin->setTemplate($format); } $plugin->addSubscriber($logPlugin); } }
/** * Add the exponential backoff logger to the backoff plugin * * @param BackoffPlugin $plugin Plugin to attach a logger to * @param mixed $logger Logger to use with the plugin * @param string $format Logger format option * * @throws InvalidArgumentException if the logger is not valid */ private function addLogger(BackoffPlugin $plugin, $logger, $format = null) { if ($logger === 'debug') { $logger = new ClosureLogAdapter(function ($message) { trigger_error($message . "\n"); }); } elseif (!$logger instanceof LogAdapterInterface) { throw new InvalidArgumentException(Options::BACKOFF_LOGGER . ' must be set to `debug` or an instance of ' . 'Guzzle\\Common\\Log\\LogAdapterInterface'); } // Create the plugin responsible for logging exponential backoff retries $logPlugin = new BackoffLogger($logger); // You can specify a custom format or use the default if ($format) { $logPlugin->setTemplate($format); } $plugin->addSubscriber($logPlugin); }