Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Enable debug without constants (issue #62) #63

Open
wants to merge 2 commits into from

4 participants

Erich Beyrent Alvaro Videla Johannes Filip Procházka
Erich Beyrent

Added support for callers to enable and disable channel debug output
without setting a constant.

Erich Beyrent ebeyrent videlalvaro#62
Added support for callers to enable and disable channel debug output
without setting a constant.
765d975
Alvaro Videla
Owner

Would you mind updating the README as well. So next to where it mentions the AMQP_DEBUG constant, also document this behaviors

Johannes

How about adding this as a constructor argument?

Alvaro Videla
Owner

@schmittjoh I thought about it… but there are way too many already, but it could be an option to consider

Johannes

Maybe add a builder class for the connection?

ConnectionBuilder::create()
   ->setHost()
   // ...
   ->enableDebug()
   ->build();
Erich Beyrent

I guess it depends on whether or not debug should be global, or on a channel-by-channel basis.

Filip Procházka

The "constants configuration" is actually pretty awfull. I really like this change, will you please rebase it so it can be merged?

Alvaro Videla
Owner

Note that due to performance reasons we need this change to happen before any connection is attempted, which probably means changing the API

Filip Procházka

@videlalvaro even when the act of connecting is lazy?

Alvaro Videla
Owner

If the connection is lazy, then that's fine

Filip Procházka

I'm debating whether whether I should send a pull in which I'd make this always lazy, because there is really no reason not to be always lazy, or implement this enableDebugmethod in the upper application layer by extending the connection class. Any thoughts?

Alvaro Videla
Owner

As always keep in mind other people code, we don't want to break things :)

Filip Procházka

I know that, but I hoped you'd tell me if you know about some possible issues when you not connect lazily. So I could fix them, or drop the case if not possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 17, 2013
  1. Erich Beyrent

    videlalvaro#62

    ebeyrent authored
    Added support for callers to enable and disable channel debug output
    without setting a constant.
  2. Erich Beyrent
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 3 deletions.
  1. +28 −1 PhpAmqpLib/Channel/AbstractChannel.php
  2. +10 −2 README.md
29 PhpAmqpLib/Channel/AbstractChannel.php
View
@@ -20,7 +20,12 @@ class AbstractChannel
{
public static $PROTOCOL_CONSTANTS_CLASS;
- protected $debug;
+ /**
+ *
+ * @var boolean
+ */
+ protected $debug = false;
+
/**
*
* @var AMQPConnection
@@ -68,6 +73,28 @@ public function __construct(AMQPConnection $connection, $channel_id)
}
}
+ /**
+ * Disables output of channel debug data
+ *
+ * @return \PhpAmqpLib\Channel\AbstractChannel
+ */
+ public function disableDebug()
+ {
+ $this->debug = false;
+ return $this;
+ }
+
+ /**
+ * Enables output of channel debug data
+ *
+ * @return \PhpAmqpLib\Channel\AbstractChannel
+ */
+ public function enableDebug()
+ {
+ $this->debug = true;
+ return $this;
+ }
+
public function getChannelId()
{
return $this->channel_id;
12 README.md
View
@@ -76,14 +76,22 @@ $ php amqp_consumer_non_blocking.php
## Debugging ##
-If you want to know what's going on at a protocol level then add the following constant to your code:
+If you want to know what's going on at a protocol level then call the enableDebug() method in the AMQPChannel object:
```php
<?php
-define('AMQP_DEBUG', true);
+$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
+$ch = $conn->channel();
+
+// Enable debug at the protocol level
+$ch->enableDebug();
... more code
+// Disable debug
+$ch->disableDebug();
+
+
?>
```
Something went wrong with that request. Please try again.