PROTON-1237: c: connection_engine event logging.

Environment variable PN_TRACE_EVENT=1 prints proton C event names using the
transport trace log facility. Mostly useful for low-level debugging while doing
binding work but might be of use to users in some cases.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/e9f9eef0
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/e9f9eef0
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/e9f9eef0

Branch: refs/heads/master
Commit: e9f9eef00e50f93c49f2eeec66bcfa9045e771d6
Parents: 1c2dd81
Author: Alan Conway <[email protected]>
Authored: Fri Jul 15 17:21:53 2016 -0400
Committer: Alan Conway <[email protected]>
Committed: Fri Jul 15 17:21:53 2016 -0400

----------------------------------------------------------------------
 .../bindings/cpp/src/io/connection_engine.cpp   |  2 --
 proton-c/src/engine/connection_engine.c         | 25 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e9f9eef0/proton-c/bindings/cpp/src/io/connection_engine.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/io/connection_engine.cpp 
b/proton-c/bindings/cpp/src/io/connection_engine.cpp
index d17f26f..5c2c092 100644
--- a/proton-c/bindings/cpp/src/io/connection_engine.cpp
+++ b/proton-c/bindings/cpp/src/io/connection_engine.cpp
@@ -38,8 +38,6 @@
 
 #include <iosfwd>
 
-#include <assert.h>
-
 namespace proton {
 namespace io {
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e9f9eef0/proton-c/src/engine/connection_engine.c
----------------------------------------------------------------------
diff --git a/proton-c/src/engine/connection_engine.c 
b/proton-c/src/engine/connection_engine.c
index 87f1177..ab4f927 100644
--- a/proton-c/src/engine/connection_engine.c
+++ b/proton-c/src/engine/connection_engine.c
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+#include "util.h"
+
 #include <proton/connection.h>
 #include <proton/connection_engine.h>
 #include <proton/transport.h>
@@ -103,10 +105,33 @@ void 
pn_connection_engine_disconnected(pn_connection_engine_t* e) {
     pn_connection_engine_write_close(e);
 }
 
+enum { LOG_DISABLED, LOG_ENABLED, LOG_UNKNOWN };
+
+static void log_event(pn_connection_engine_t *engine, pn_event_t* event) {
+    if (!event)
+        return;
+    static int enabled = LOG_UNKNOWN;
+    // Switch so this can be evaluated as a single branch.
+    switch (enabled) {
+      case LOG_DISABLED:
+        return;
+      case LOG_ENABLED:
+        pn_transport_log(engine->transport, 
pn_event_type_name(pn_event_type(event)));
+        return;
+      case LOG_UNKNOWN:
+        enabled = pn_env_bool("PN_TRACE_EVENT") ? LOG_ENABLED : LOG_DISABLED;
+        if (enabled == LOG_ENABLED) {
+            pn_transport_log(engine->transport, 
pn_event_type_name(pn_event_type(event)));
+        }
+        return;
+    }
+}
+
 pn_event_t* pn_connection_engine_dispatch(pn_connection_engine_t* e) {
     if (e->event)
         pn_collector_pop(e->collector);
     e->event = pn_collector_peek(e->collector);
+    log_event(e, e->event);
     return e->event;
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to