Skip to content

Commit

Permalink
update to use packaged/log (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK authored Nov 14, 2024
1 parent d533348 commit a0d4540
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"ext-json": "*",
"php": ">=7.1.0",
"packaged/config": "^1.1",
"packaged/helpers": "^1.0|^2.0"
"packaged/helpers": "^1.0|^2.0",
"packaged/log": "^1.1"
},
"suggest": {
"php-amqplib/php-amqplib": "Enables using queues in RabbitMQ",
Expand Down
5 changes: 3 additions & 2 deletions src/Provider/AbstractQueueProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Packaged\Config\ConfigSectionInterface;
use Packaged\Config\ConfigurableInterface;
use Packaged\Config\Provider\ConfigSection;
use Packaged\Log\Log;
use Packaged\Queue\IQueueProvider;

abstract class AbstractQueueProvider
Expand Down Expand Up @@ -56,7 +57,7 @@ protected function _construct()
*/
public static function create($queueName)
{
$object = new static;
$object = new static();
$object->_queueName = $queueName;
return $object;
}
Expand Down Expand Up @@ -102,6 +103,6 @@ protected function _processBatchMessage($msg)

protected function _log($message)
{
error_log('Queue (' . $this->_getQueueName() . '): ' . $message);
Log::debug('Queue (' . $this->_getQueueName() . '): ' . $message);
}
}
14 changes: 6 additions & 8 deletions src/Provider/Amqp/AmqpQueueProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Exception;
use Packaged\Helpers\ValueAs;
use Packaged\Log\Log;
use Packaged\Queue\IBatchQueueProvider;
use Packaged\Queue\Provider\AbstractQueueProvider;
use Packaged\Queue\Provider\QueueConnectionException;
Expand Down Expand Up @@ -155,7 +156,7 @@ public function pushBatch(array $batch, $persistent = null)

if($needDeclare)
{
$this->_log("Auto-declaring exchange and queue");
Log::debug("Auto-declaring exchange and queue");
$declareAttempts++;
$this->declareExchange();
$this->declareQueue();
Expand Down Expand Up @@ -226,10 +227,7 @@ public function push($data, $persistent = null)
$duration = (microtime(true) - $startTime) * 1000;
if($duration > $this->_slowPushThreshold)
{
error_log(
'Slow push to queue ' . $this->_queueName . ' took '
. round($duration, 1) . 'ms'
);
Log::warning('Slow push to queue. took ' . round($duration, 1) . 'ms');
}
}
return $this;
Expand Down Expand Up @@ -579,7 +577,7 @@ protected function _getConnection($connectionMode)
}
catch(Exception $e)
{
$this->_log('AMQP host failed to connect [' . $e->getMessage() . '] (' . $host . ')');
Log::error('AMQP host failed to connect [' . $e->getMessage() . '] (' . $host . ')');
array_shift($this->_hosts);
}
$this->_persistentDefault = ValueAs::bool($config->getItem('persistent', false));
Expand All @@ -597,7 +595,7 @@ protected function _getConnection($connectionMode)
}
catch(AMQPRuntimeException $e)
{
$this->_log('Unable to start heartbeat sender. ' . $e->getMessage());
Log::error('Unable to start heartbeat sender. ' . $e->getMessage());
}

return $this->_connections[$connectionMode];
Expand Down Expand Up @@ -639,7 +637,7 @@ protected function _getChannel($connectionMode)
}
catch(Exception $e)
{
$this->_log(
Log::error(
'Error getting AMQP channel [' . $e->getMessage() . '] (' . $retries . ' retries remaining) '
);
$this->disconnect($connectionMode);
Expand Down
7 changes: 4 additions & 3 deletions src/Provider/Google/GooglePubSubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Google\Cloud\PubSub\Subscription;
use Google\Cloud\PubSub\Topic;
use Packaged\Helpers\ValueAs;
use Packaged\Log\Log;
use Packaged\Queue\IBatchQueueProvider;
use Packaged\Queue\Provider\AbstractQueueProvider;
use Packaged\Queue\Provider\QueueCredentialsException;
Expand Down Expand Up @@ -144,14 +145,14 @@ private function _createTopicAndSub()
{
try
{
$this->_log('Auto-creating subscription ' . $this->_getSubscription()->name());
Log::debug('Auto-creating subscription ' . $this->_getSubscription()->name());
$this->_getSubscription()->create($subscriptionOpts);
}
catch(NotFoundException $e)
{
try
{
$this->_log('Auto-creating topic ' . $this->_getTopic()->name());
Log::debug('Auto-creating topic ' . $this->_getTopic()->name());
$this->_getTopic()->create();
}
catch(ConflictException $e)
Expand All @@ -162,7 +163,7 @@ private function _createTopicAndSub()
}
}

$this->_log('Auto-creating subscription ' . $this->_getSubscription()->name() . " (second attempt)");
Log::debug('Auto-creating subscription ' . $this->_getSubscription()->name() . " (second attempt)");
$this->_getSubscription()->create($subscriptionOpts);
}
}
Expand Down

0 comments on commit a0d4540

Please sign in to comment.