PROTON-1237: Improve connection_engine event logging
diff --git a/proton-c/include/proton/transport.h b/proton-c/include/proton/transport.h
index cfa6d71..5c8494c 100644
--- a/proton-c/include/proton/transport.h
+++ b/proton-c/include/proton/transport.h
@@ -52,6 +52,7 @@
* - ::PN_TRACE_RAW
* - ::PN_TRACE_FRM
* - ::PN_TRACE_DRV
+ * - ::PN_TRACE_EVT
*
*/
typedef int pn_trace_t;
@@ -82,6 +83,11 @@
#define PN_TRACE_DRV (4)
/**
+ * Log events
+ */
+#define PN_TRACE_EVT (8)
+
+/**
* Factory for creating a transport.
* A transport is used by a connection to interface with the network.
* There can only be one connection associated with a transport. See
diff --git a/proton-c/src/engine/connection_engine.c b/proton-c/src/engine/connection_engine.c
index ab4f927..75a16ae 100644
--- a/proton-c/src/engine/connection_engine.c
+++ b/proton-c/src/engine/connection_engine.c
@@ -16,8 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-#include "util.h"
+#include "engine-internal.h"
#include <proton/connection.h>
#include <proton/connection_engine.h>
@@ -105,25 +104,12 @@
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;
+ if (event && engine->transport->trace & PN_TRACE_EVT) {
+ pn_string_t *str = pn_string(NULL);
+ pn_inspect(event, str);
+ pn_transport_log(engine->transport, pn_string_get(str));
+ pn_free(str);
}
}
diff --git a/proton-c/src/transport/transport.c b/proton-c/src/transport/transport.c
index 07ee1f6..1d7cc87 100644
--- a/proton-c/src/transport/transport.c
+++ b/proton-c/src/transport/transport.c
@@ -486,9 +486,11 @@
transport->referenced = true;
- transport->trace = (pn_env_bool("PN_TRACE_RAW") ? PN_TRACE_RAW : PN_TRACE_OFF) |
+ transport->trace =
+ (pn_env_bool("PN_TRACE_RAW") ? PN_TRACE_RAW : PN_TRACE_OFF) |
(pn_env_bool("PN_TRACE_FRM") ? PN_TRACE_FRM : PN_TRACE_OFF) |
- (pn_env_bool("PN_TRACE_DRV") ? PN_TRACE_DRV : PN_TRACE_OFF);
+ (pn_env_bool("PN_TRACE_DRV") ? PN_TRACE_DRV : PN_TRACE_OFF) |
+ (pn_env_bool("PN_TRACE_EVT") ? PN_TRACE_EVT : PN_TRACE_OFF) ;
}