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

@ebeyrent

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

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

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

@schmittjoh

How about adding this as a constructor argument?

@videlalvaro
Owner

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

@schmittjoh

Maybe add a builder class for the connection?

ConnectionBuilder::create()
   ->setHost()
   // ...
   ->enableDebug()
   ->build();
@ebeyrent

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

@fprochazka

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

@videlalvaro
Owner

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

@fprochazka

@videlalvaro even when the act of connecting is lazy?

@videlalvaro
Owner

If the connection is lazy, then that's fine

@fprochazka

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?

@videlalvaro
Owner

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

@fprochazka

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. @ebeyrent

    videlalvaro#62

    ebeyrent authored
    Added support for callers to enable and disable channel debug output
    without setting a constant.
  2. @ebeyrent
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
View
29 PhpAmqpLib/Channel/AbstractChannel.php
@@ -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;
View
12 README.md
@@ -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.