mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject incubator-mynewt-core git commit: oic; use OC_LOG_XXX macros for logging.
Date Sat, 10 Dec 2016 08:00:21 GMT
Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop c8503b7ac -> 78fc17921


oic; use OC_LOG_XXX macros for logging.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/78fc1792
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/78fc1792
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/78fc1792

Branch: refs/heads/develop
Commit: 78fc17921699143a65a0de2b1b7df26c50723883
Parents: c8503b7
Author: Marko Kiiskila <marko@runtime.io>
Authored: Fri Dec 9 23:59:35 2016 -0800
Committer: Marko Kiiskila <marko@runtime.io>
Committed: Fri Dec 9 23:59:35 2016 -0800

----------------------------------------------------------------------
 apps/ocf_sample/src/main.c                | 58 ++++++++--------
 net/oic/include/oic/oc_log.h              | 66 ++++++++----------
 net/oic/src/api/oc_buffer.c               | 26 ++++---
 net/oic/src/api/oc_main.c                 |  4 +-
 net/oic/src/api/oc_ri.c                   | 10 +--
 net/oic/src/messaging/coap/coap.c         | 93 +++++++++++++-------------
 net/oic/src/messaging/coap/coap.h         | 21 +++---
 net/oic/src/messaging/coap/engine.c       | 36 ++++------
 net/oic/src/messaging/coap/observe.c      | 31 +++------
 net/oic/src/messaging/coap/separate.c     |  2 +-
 net/oic/src/messaging/coap/transactions.c | 19 ++----
 net/oic/src/port/mynewt/adaptor.c         |  2 +-
 net/oic/src/port/mynewt/ble_adaptor.c     | 28 ++------
 net/oic/src/port/mynewt/ip_adaptor.c      | 38 ++++-------
 net/oic/src/port/mynewt/serial_adaptor.c  | 12 +---
 net/oic/src/port/oc_assert.h              | 24 ++-----
 16 files changed, 194 insertions(+), 276 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index 096b444..bd6d7e1 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -51,7 +51,7 @@ static bool light_state = false;
 static void
 get_light(oc_request_t *request, oc_interface_mask_t interface)
 {
-    PRINT("GET_light:\n");
+    printf("GET_light:\n");
     oc_rep_start_root_object();
     switch (interface) {
         case OC_IF_BASELINE:
@@ -64,21 +64,21 @@ get_light(oc_request_t *request, oc_interface_mask_t interface)
     }
     oc_rep_end_root_object();
     oc_send_response(request, OC_STATUS_OK);
-    PRINT("Light state %d\n", light_state);
+    printf("Light state %d\n", light_state);
 }
 
 static void
 put_light(oc_request_t *request, oc_interface_mask_t interface)
 {
-    PRINT("PUT_light:\n");
+    printf("PUT_light:\n");
     bool state = false;
     oc_rep_t *rep = request->request_payload;
     while (rep != NULL) {
-        PRINT("key: %s ", oc_string(rep->name));
+        printf("key: %s ", oc_string(rep->name));
         switch (rep->type) {
             case BOOL:
                 state = rep->value_boolean;
-                PRINT("value: %d\n", state);
+                printf("value: %d\n", state);
                 break;
             default:
                 oc_send_response(request, OC_STATUS_BAD_REQUEST);
@@ -94,16 +94,16 @@ put_light(oc_request_t *request, oc_interface_mask_t interface)
 static void
 register_resources(void)
 {
-  oc_resource_t *res = oc_new_resource("/light/1", 1, 0);
-  oc_resource_bind_resource_type(res, "oic.r.light");
-  oc_resource_bind_resource_interface(res, OC_IF_RW);
-  oc_resource_set_default_interface(res, OC_IF_RW);
-
-  oc_resource_set_discoverable(res);
-  oc_resource_set_periodic_observable(res, 1);
-  oc_resource_set_request_handler(res, OC_GET, get_light);
-  oc_resource_set_request_handler(res, OC_PUT, put_light);
-  oc_add_resource(res);
+    oc_resource_t *res = oc_new_resource("/light/1", 1, 0);
+    oc_resource_bind_resource_type(res, "oic.r.light");
+    oc_resource_bind_resource_interface(res, OC_IF_RW);
+    oc_resource_set_default_interface(res, OC_IF_RW);
+
+    oc_resource_set_discoverable(res);
+    oc_resource_set_periodic_observable(res, 1);
+    oc_resource_set_request_handler(res, OC_GET, get_light);
+    oc_resource_set_request_handler(res, OC_PUT, put_light);
+    oc_add_resource(res);
 }
 #endif
 
@@ -123,30 +123,30 @@ set_device_custom_property(void *data)
 static void
 stop_observe(struct os_event *ev)
 {
-    PRINT("Stopping OBSERVE\n");
+    printf("Stopping OBSERVE\n");
     oc_stop_observe(light_1, &light_server);
 }
 
 static void
 put_light(oc_client_response_t *data)
 {
-    PRINT("PUT_light:\n");
+    printf("PUT_light:\n");
     if (data->code == OC_STATUS_CHANGED)
-        PRINT("PUT response OK\n");
+        printf("PUT response OK\n");
     else
-        PRINT("PUT response code %d\n", data->code);
+        printf("PUT response code %d\n", data->code);
 }
 
 static void
 observe_light(oc_client_response_t *data)
 {
-    PRINT("OBSERVE_light:\n");
+    printf("OBSERVE_light:\n");
     oc_rep_t *rep = data->payload;
     while (rep != NULL) {
-        PRINT("key %s, value ", oc_string(rep->name));
+        printf("key %s, value ", oc_string(rep->name));
         switch (rep->type) {
             case BOOL:
-                PRINT("%d\n", rep->value_boolean);
+                printf("%d\n", rep->value_boolean);
                 light_state = rep->value_boolean;
                 break;
             default:
@@ -159,12 +159,14 @@ observe_light(oc_client_response_t *data)
         oc_rep_start_root_object();
         oc_rep_set_boolean(root, state, !light_state);
         oc_rep_end_root_object();
-        if (oc_do_put())
-            PRINT("Sent PUT request\n");
-        else
-            PRINT("Could not send PUT\n");
-    } else
-        PRINT("Could not init PUT\n");
+        if (oc_do_put()) {
+            printf("Sent PUT request\n");
+        } else {
+            printf("Could not send PUT\n");
+        }
+    } else {
+        printf("Could not init PUT\n");
+    }
 }
 
 static oc_discovery_flags_t

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/include/oic/oc_log.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_log.h b/net/oic/include/oic/oc_log.h
index 547f452..ab3ca66 100644
--- a/net/oic/include/oic/oc_log.h
+++ b/net/oic/include/oic/oc_log.h
@@ -24,46 +24,36 @@
 extern "C" {
 #endif
 
-
-#define PRINT(...) printf(__VA_ARGS__)
-
-#define PRINTipaddr(endpoint)                                                  \
-  PRINT(                                                                      \
-    "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%"    \
-    "02x]:%d",                                                                 \
-    ((endpoint).ipv6_addr.address)[0], ((endpoint).ipv6_addr.address)[1],      \
-    ((endpoint).ipv6_addr.address)[2], ((endpoint).ipv6_addr.address)[3],      \
-    ((endpoint).ipv6_addr.address)[4], ((endpoint).ipv6_addr.address)[5],      \
-    ((endpoint).ipv6_addr.address)[6], ((endpoint).ipv6_addr.address)[7],      \
-    ((endpoint).ipv6_addr.address)[8], ((endpoint).ipv6_addr.address)[9],      \
-    ((endpoint).ipv6_addr.address)[10], ((endpoint).ipv6_addr.address)[11],    \
-    ((endpoint).ipv6_addr.address)[12], ((endpoint).ipv6_addr.address)[13],    \
-    ((endpoint).ipv6_addr.address)[14], ((endpoint).ipv6_addr.address)[15],    \
-    (endpoint).ipv6_addr.port)
-
-#define LogMynewtipaddr(endpoint)                                                  \
-{\
-  char tmp_buf[16*3+6]; /* 16 octets plus port */                              \
-  sprintf(tmp_buf,                                                             \
-    "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%"    \
-    "02x]:%d",                                                                 \
-    ((endpoint).ipv6_addr.address)[0], ((endpoint).ipv6_addr.address)[1],      \
-    ((endpoint).ipv6_addr.address)[2], ((endpoint).ipv6_addr.address)[3],      \
-    ((endpoint).ipv6_addr.address)[4], ((endpoint).ipv6_addr.address)[5],      \
-    ((endpoint).ipv6_addr.address)[6], ((endpoint).ipv6_addr.address)[7],      \
-    ((endpoint).ipv6_addr.address)[8], ((endpoint).ipv6_addr.address)[9],      \
-    ((endpoint).ipv6_addr.address)[10], ((endpoint).ipv6_addr.address)[11],    \
-    ((endpoint).ipv6_addr.address)[12], ((endpoint).ipv6_addr.address)[13],    \
-    ((endpoint).ipv6_addr.address)[14], ((endpoint).ipv6_addr.address)[15],    \
-    (endpoint).ipv6_addr.port);                                                \
-    LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY, "%s", tmp_buf);                     \
-}
-
 extern struct log oc_log;
+
 #define OC_LOG_DEBUG(...) LOG_DEBUG(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
-#define LOG(...) LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
-#define ERROR(...) LOG_ERROR(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
-#define LOGipaddr(endpoint) LogMynewtipaddr(endpoint)
+#define OC_LOG_INFO(...) LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
+#define OC_LOG_ERROR(...) LOG_ERROR(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
+
+struct oc_endpoint;
+void oc_log_endpoint(uint16_t lvl, struct oc_endpoint *);
+void oc_log_bytes(uint16_t lvl, void *addr, int len, int print_char);
+
+#define OC_LOG_ENDPOINT(lvl, ep)                                        \
+    do {                                                                \
+        if (MYNEWT_VAL(LOG_LEVEL) <= (lvl)) {                           \
+            oc_log_endpoint(lvl, ep);                                   \
+        }                                                               \
+    } while(0)
+
+#define OC_LOG_STR(lvl, addr, len)                                      \
+    do {                                                                \
+        if (MYNEWT_VAL(LOG_LEVEL) <= (lvl)) {                           \
+            oc_log_bytes(lvl, addr, len, 1);                            \
+        }                                                               \
+    } while(0)
+
+#define OC_LOG_HEX(lvl, addr, len)                                      \
+    do {                                                                \
+        if (MYNEWT_VAL(LOG_LEVEL) <= (lvl)) {                           \
+            oc_log_bytes(lvl, addr, len, 0);                            \
+        }                                                               \
+    } while(0)
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index e9dc35a..6fb6beb 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -47,10 +47,10 @@ oc_allocate_message(void)
     if (message) {
         message->length = 0;
         message->ref_count = 1;
-        LOG("buffer: Allocated TX/RX buffer; num free: %d\n",
+        OC_LOG_DEBUG("buffer: Allocated oc_message; free: %d\n",
           oc_buffers.mp_num_free);
     } else {
-        LOG("buffer: No free TX/RX buffers!\n");
+        OC_LOG_ERROR("buffer: No free oc_mesages!\n");
         assert(0);
     }
     return message;
@@ -85,7 +85,7 @@ oc_message_unref(oc_message_t *message)
         message->ref_count--;
         if (message->ref_count == 0) {
             os_memblock_put(&oc_buffers, message);
-            LOG("buffer: freed TX/RX buffer; num free: %d\n",
+            OC_LOG_DEBUG("buffer: freed oc_message; free: %d\n",
               oc_buffers.mp_num_free);
         }
     }
@@ -115,30 +115,28 @@ oc_buffer_tx(struct os_event *ev)
     struct os_mbuf *m;
 
     while ((m = os_mqueue_get(&oc_outq)) != NULL) {
+        OC_LOG_DEBUG("oc_buffer_tx");
+        OC_LOG_ENDPOINT(LOG_LEVEL_DEBUG, OC_MBUF_ENDPOINT(m));
 #ifdef OC_CLIENT
         if (OC_MBUF_ENDPOINT(m)->flags & MULTICAST) {
-            LOG("oc_buffer_tx: multicast\n");
             oc_send_multicast_message(m);
         } else {
 #endif
 #ifdef OC_SECURITY
             /* XXX convert this */
             if (OC_MBUF_ENDPOINT(m)->flags & SECURED) {
-                LOG("oc_buffer_tx: DTLS\n");
+                OC_LOG_DEBUG("oc_buffer_tx: DTLS\n");
 
                 if (!oc_sec_dtls_connected(oe)) {
-                    LOG("oc_buffer_tx: INIT_DTLS_CONN_EVENT\n");
                     oc_process_post(&oc_dtls_handler,
                                     oc_events[INIT_DTLS_CONN_EVENT], m);
                 } else {
-                    LOG("oc_buffer_tx: RI_TO_DTLS_EVENT\n");
                     oc_process_post(&oc_dtls_handler,
                                     oc_events[RI_TO_DTLS_EVENT], m);
                 }
             } else
 #endif
             {
-                LOG("oc_buffer_tx: unicast\n");
                 oc_send_buffer(m);
             }
 #ifdef OC_CLIENT
@@ -159,15 +157,17 @@ oc_buffer_rx(struct os_event *ev)
     while ((m = os_mqueue_get(&oc_inq)) != NULL) {
         msg = oc_allocate_message();
         if (!msg) {
-            ERROR("Could not allocate OC message buffer\n");
             goto free_msg;
         }
+        OC_LOG_DEBUG("oc_buffer_rx: ");
+        OC_LOG_ENDPOINT(LOG_LEVEL_DEBUG, &msg->endpoint);
+
         if (OS_MBUF_PKTHDR(m)->omp_len > MAX_PAYLOAD_SIZE) {
-            ERROR("Message to large for OC message buffer\n");
+            STATS_INC(coap_stats, itoobig);
             goto free_msg;
         }
         if (os_mbuf_copydata(m, 0, OS_MBUF_PKTHDR(m)->omp_len, msg->data)) {
-            ERROR("Failed to copy message from mbuf to OC message buffer \n");
+            STATS_INC(coap_stats, imem);
             goto free_msg;
         }
         memcpy(&msg->endpoint, OC_MBUF_ENDPOINT(m), sizeof(msg->endpoint));
@@ -176,15 +176,13 @@ oc_buffer_rx(struct os_event *ev)
 #ifdef OC_SECURITY
         b = m->om_data[0];
         if (b > 19 && b < 64) {
-            LOG("Inbound network event: encrypted request\n");
+            OC_LOG_DEBUG("oc_buffer_rx: encrypted request\n");
             oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], m);
         } else {
-            LOG("Inbound network event: decrypted request\n");
             coap_receive(msg);
             oc_message_unref(msg);
         }
 #else
-        LOG("Inbound network event: decrypted request\n");
         coap_receive(msg);
         oc_message_unref(msg);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/api/oc_main.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_main.c b/net/oic/src/api/oc_main.c
index 1979e51..f84c2cd 100644
--- a/net/oic/src/api/oc_main.c
+++ b/net/oic/src/api/oc_main.c
@@ -77,7 +77,7 @@ oc_main_init(oc_handler_t *handler)
         goto err;
     }
 
-    PRINT("oci: Initialized\n");
+    OC_LOG_INFO("oci: Initialized\n");
 
 #ifdef OC_CLIENT
     handler->requests_entry();
@@ -101,7 +101,7 @@ void
 oc_main_shutdown(void)
 {
     if (initialized == false) {
-        PRINT("oci: not initialized\n");
+        OC_LOG_ERROR("oci: not initialized\n");
         return;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 9c84e01..d240193 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -433,7 +433,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
      * request and results in a 4.00 response being sent.
      */
     if (oc_parse_rep(payload, payload_len, &request_obj.request_payload) != 0) {
-      LOG("ocri: error parsing request payload\n");
+      OC_LOG_ERROR("ocri: error parsing request payload\n");
       bad_request = true;
     }
   }
@@ -538,18 +538,18 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
   }
 
   if (bad_request) {
-    LOG("ocri: Bad request\n");
+    OC_LOG_ERROR("ocri: Bad request\n");
     /* Return a 4.00 response */
     response_buffer.code = oc_status_code(OC_STATUS_BAD_REQUEST);
     success = false;
   } else if (!cur_resource) {
-    LOG("ocri: Could not find resource\n");
+    OC_LOG_ERROR("ocri: Could not find resource\n");
     /* Return a 4.04 response if the requested resource was not found */
     response_buffer.response_length = 0;
     response_buffer.code = oc_status_code(OC_STATUS_NOT_FOUND);
     success = false;
   } else if (!method_impl) {
-    LOG("ocri: Could not find method\n");
+    OC_LOG_ERROR("ocri: Could not find method\n");
     /* Return a 4.05 response if the resource does not implement the
      * request method.
      */
@@ -559,7 +559,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
   }
 #ifdef OC_SECURITY
   else if (!authorized) {
-    LOG("ocri: Subject not authorized\n");
+    OC_LOG_ERROR("ocri: Subject not authorized\n");
     /* If the requestor (subject) does not have access granted via an
      * access control entry in the ACL, then it is not authorized to
      * access the resource. A 4.03 response is sent.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index 2cea8c4..d4cb082 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -47,6 +47,8 @@ STATS_SECT_DECL(coap_stats) coap_stats;
 STATS_NAME_START(coap_stats)
     STATS_NAME(coap_stats, iframe)
     STATS_NAME(coap_stats, ierr)
+    STATS_NAME(coap_stats, itoobig)
+    STATS_NAME(coap_stats, imem)
     STATS_NAME(coap_stats, oframe)
     STATS_NAME(coap_stats, oerr)
 STATS_NAME_END(coap_stats)
@@ -146,7 +148,8 @@ coap_append_int_opt(struct os_mbuf *m, unsigned int number,
     if (0xFFFFFFFF & value) {
         ++i;
     }
-    LOG("OPTION %u (delta %u, len %zu)\n", number, number - current_number, i);
+    OC_LOG_DEBUG("OPTION %u (delta %u, len %zu)\n",
+                 number, number - current_number, i);
 
     rc = coap_append_opt_hdr(m, number - current_number, i);
     if (rc) {
@@ -180,11 +183,10 @@ coap_append_array_opt(struct os_mbuf *m,
     uint8_t *part_end = NULL;
     size_t blk;
 
-    LOG("ARRAY type %u, len %zu\n", number, length);
+    OC_LOG_DEBUG("ARRAY type %u, len %zu\n", number, length);
 
     if (split_char != '\0') {
         for (j = 0; j <= length + 1; ++j) {
-            LOG("STEP %u/%zu (%c)\n", j, length, array[j]);
             if (array[j] == split_char || j == length) {
                 part_end = array + j;
                 blk = part_end - part_start;
@@ -198,7 +200,7 @@ coap_append_array_opt(struct os_mbuf *m,
                     return rc;
                 }
 
-                LOG("OPTION type %u, delta %u, len %zu\n", number,
+                OC_LOG_DEBUG("OPTION type %u, delta %u, len %zu\n", number,
                     number - current_number, (int)blk);
 
                 ++j; /* skip the splitter */
@@ -216,7 +218,7 @@ coap_append_array_opt(struct os_mbuf *m,
             return rc;
         }
 
-        LOG("OPTION type %u, delta %u, len %zu\n", number,
+        OC_LOG_DEBUG("OPTION type %u, delta %u, len %zu\n", number,
             number - current_number, length);
     }
 
@@ -330,7 +332,7 @@ coap_serialize_message(coap_packet_t *pkt, struct os_mbuf *m)
     /* Initialize */
     pkt->version = 1;
 
-    LOG("-Serializing message %u to 0x%x, ", pkt->mid, (unsigned)m);
+    OC_LOG_DEBUG("coap_tx: 0x%x\n", (unsigned)m);
 
     tcp_hdr = oc_endpoint_use_tcp(OC_MBUF_ENDPOINT(m));
 
@@ -362,7 +364,7 @@ coap_serialize_message(coap_packet_t *pkt, struct os_mbuf *m)
 #endif
     COAP_SERIALIZE_STRING_OPT(pkt, m, COAP_OPTION_URI_PATH, uri_path, '/',
                               "Uri-Path");
-    LOG("Serialize content format: %d\n", pkt->content_format);
+
     COAP_SERIALIZE_INT_OPT(pkt, m, COAP_OPTION_CONTENT_FORMAT, content_format,
                            "Content-Format");
 #if 0
@@ -448,7 +450,7 @@ coap_serialize_message(coap_packet_t *pkt, struct os_mbuf *m)
         goto err_mem;
     }
 
-    LOG("-Done %u B (header len %u, payload len %u)-\n",
+    OC_LOG_DEBUG("coap_tx: serialized %u B (header len %u, payload len %u)\n",
         OS_MBUF_PKTLEN(m), OS_MBUF_PKTLEN(m) - pkt->payload_len,
         pkt->payload_len);
 
@@ -461,7 +463,7 @@ err_mem:
 void
 coap_send_message(struct os_mbuf *m, int dup)
 {
-    LOG("-sending OCF message (%u)-\n", OS_MBUF_PKTLEN(m));
+    OC_LOG_INFO("coap_send_message(): (%u)\n", OS_MBUF_PKTLEN(m));
 
     STATS_INC(coap_stats, oframe);
 
@@ -583,10 +585,8 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
 
     memcpy(pkt->token, cur_opt, pkt->token_len);
 
-    LOG("Token (len %u) [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
-      pkt->token_len,
-      pkt->token[0], pkt->token[1], pkt->token[2], pkt->token[3], pkt->token[4],
-      pkt->token[5], pkt->token[6], pkt->token[7]); /* XXX always prints 8 */
+    OC_LOG_DEBUG("Token (len %u) ");
+    OC_LOG_HEX(LOG_LEVEL_DEBUG, pkt->token, pkt->token_len);
 
     /* parse options */
     memset(pkt->options, 0, sizeof(pkt->options));
@@ -632,48 +632,43 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
         opt_num += opt_delta;
 
         if (opt_num < COAP_OPTION_SIZE1) {
-            LOG("OPTION %u (delta %u, len %zu): ", opt_num, opt_delta, opt_len);
+            OC_LOG_DEBUG("OPTION %u (delta %u, len %zu): ",
+                         opt_num, opt_delta, opt_len);
             SET_OPTION(pkt, opt_num);
         }
 
         switch (opt_num) {
         case COAP_OPTION_CONTENT_FORMAT:
             pkt->content_format = coap_parse_int_option(cur_opt, opt_len);
-            LOG("Content-Format [%u]\n", pkt->content_format);
+            OC_LOG_DEBUG("Content-Format [%u]\n", pkt->content_format);
             break;
         case COAP_OPTION_MAX_AGE:
             pkt->max_age = coap_parse_int_option(cur_opt, opt_len);
-            LOG("Max-Age [%lu]\n", (unsigned long)pkt->max_age);
+            OC_LOG_DEBUG("Max-Age [%lu]\n", (unsigned long)pkt->max_age);
             break;
 #if 0
         case COAP_OPTION_ETAG:
             pkt->etag_len = MIN(COAP_ETAG_LEN, opt_len);
             memcpy(pkt->etag, cur_opt, pkt->etag_len);
-            LOG("ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
-              pkt->etag_len,
-              pkt->etag[0], pkt->etag[1], pkt->etag[2], pkt->etag[3],
-              pkt->etag[4], pkt->etag[5], pkt->etag[6], pkt->etag[7]);
-            /*FIXME always prints 8 bytes */
+            OC_LOG_DEBUG("ETag %u ");
+            OC_LOG_HEX(LOG_LEVEL_DEBUG, pkt->etag, pkt->etag_len);
             break;
 #endif
         case COAP_OPTION_ACCEPT:
             pkt->accept = coap_parse_int_option(cur_opt, opt_len);
-            LOG("Accept [%u]\n", pkt->accept);
+            OC_LOG_DEBUG("Accept [%u]\n", pkt->accept);
             break;
 #if 0
         case COAP_OPTION_IF_MATCH:
             /* TODO support multiple ETags */
             pkt->if_match_len = MIN(COAP_ETAG_LEN, opt_len);
             memcpy(pkt->if_match, cur_opt, pkt->if_match_len);
-            LOG("If-Match %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
-              pkt->if_match_len, pkt->if_match[0], pkt->if_match[1],
-              pkt->if_match[2], pkt->if_match[3], pkt->if_match[4],
-              pkt->if_match[5], pkt->if_match[6], pkt->if_match[7]);
-            /* FIXME always prints 8 bytes */
+            OC_LOG_DEBUG("If-Match %u ");
+            OC_LOG_HEX(LOG_LEVEL_DEBUG, pkt->if_match, pkt->if_match_len);
             break;
         case COAP_OPTION_IF_NONE_MATCH:
             pkt->if_none_match = 1;
-            LOG("If-None-Match\n");
+            OC_LOG_DEBUG("If-None-Match\n");
             break;
 
         case COAP_OPTION_PROXY_URI:
@@ -681,7 +676,8 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
             pkt->proxy_uri = cur_opt;
             pkt->proxy_uri_len = opt_len;
 #endif
-            LOG("Proxy-Uri NOT IMPLEMENTED [%s]\n", (char *)pkt->proxy_uri);
+            OC_LOG_DEBUG("Proxy-Uri NOT IMPLEMENTED [%s]\n",
+                         (char *)pkt->proxy_uri);
             coap_error_message =
               "This is a constrained server (MyNewt)";
             STATS_INC(coap_stats, ierr);
@@ -692,7 +688,8 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
             pkt->proxy_scheme = cur_opt;
             pkt->proxy_scheme_len = opt_len;
 #endif
-            LOG("Proxy-Scheme NOT IMPLEMENTED [%s]\n", pkt->proxy_scheme);
+            OC_LOG_DEBUG("Proxy-Scheme NOT IMPLEMENTED [%s]\n",
+                         pkt->proxy_scheme);
             coap_error_message =
               "This is a constrained server (MyNewt)";
             STATS_INC(coap_stats, ierr);
@@ -702,42 +699,47 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
         case COAP_OPTION_URI_HOST:
             pkt->uri_host = cur_opt;
             pkt->uri_host_len = opt_len;
-            LOG("Uri-Host [%s]\n", (char *)pkt->uri_host);
+            OC_LOG_DEBUG("Uri-Host ");
+            OC_LOG_STR(LOG_LEVEL_DEBUG, pkt->uri_host, pkt->uri_host_len);
             break;
         case COAP_OPTION_URI_PORT:
             pkt->uri_port = coap_parse_int_option(cur_opt, opt_len);
-            LOG("Uri-Port [%u]\n", pkt->uri_port);
+            OC_LOG_DEBUG("Uri-Port [%u]\n", pkt->uri_port);
             break;
 #endif
         case COAP_OPTION_URI_PATH:
             /* coap_merge_multi_option() operates in-place on the buf */
             coap_merge_multi_option(&pkt->uri_path, &pkt->uri_path_len,
                                     cur_opt, opt_len, '/');
-            LOG("Uri-Path [%s]\n", pkt->uri_path);
+            OC_LOG_DEBUG("Uri-Path ");
+            OC_LOG_STR(LOG_LEVEL_DEBUG, pkt->uri_path, pkt->uri_path_len);
             break;
         case COAP_OPTION_URI_QUERY:
             /* coap_merge_multi_option() operates in-place on the mbuf */
             coap_merge_multi_option(&pkt->uri_query, &pkt->uri_query_len,
                                     cur_opt, opt_len, '&');
-            LOG("Uri-Query [%s]\n", pkt->uri_query);
+            OC_LOG_DEBUG("Uri-Query ");
+            OC_LOG_STR(LOG_LEVEL_DEBUG, pkt->uri_query, pkt->uri_query_len);
             break;
 #if 0
         case COAP_OPTION_LOCATION_PATH:
             /* coap_merge_multi_option() operates in-place on the mbuf */
             coap_merge_multi_option(&pkt->loc_path, &pkt->loc_path_len,
                                     cur_opt, opt_len, '/');
-            LOG("Location-Path [%s]\n", pkt->loc_path);
+            OC_LOG_DEBUG("Location-Path ");
+            OC_LOG_STR(LOG_LEVEL_DEBUG, pkt->loc_path, pkt->loc_path_len);
             break;
         case COAP_OPTION_LOCATION_QUERY:
             /* coap_merge_multi_option() operates in-place on the mbuf */
             coap_merge_multi_option(&pkt->loc_query, &pkt->loc_query_len,
                                     cur_opt, opt_len, '&');
-            LOG("Location-Query [%s]\n", pkt->loc_query);
+            OC_LOG_DEBUG("Location-Query ");
+            OC_LOG_STR(LOG_LEVEL_DEBUG, pkt->loc_query, pkt->loc_query_len);
             break;
 #endif
         case COAP_OPTION_OBSERVE:
             pkt->observe = coap_parse_int_option(cur_opt, opt_len);
-            LOG("Observe [%lu]\n", (unsigned long)pkt->observe);
+            OC_LOG_DEBUG("Observe [%lu]\n", (unsigned long)pkt->observe);
             break;
         case COAP_OPTION_BLOCK2:
             pkt->block2_num = coap_parse_int_option(cur_opt, opt_len);
@@ -746,8 +748,9 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
             pkt->block2_offset =
               (pkt->block2_num & ~0x0000000F) << (pkt->block2_num & 0x07);
             pkt->block2_num >>= 4;
-            LOG("Block2 [%lu%s (%u B/blk)]\n", (unsigned long)pkt->block2_num,
-              pkt->block2_more ? "+" : "", pkt->block2_size);
+            OC_LOG_DEBUG("Block2 [%lu%s (%u B/blk)]\n",
+                         (unsigned long)pkt->block2_num,
+                         pkt->block2_more ? "+" : "", pkt->block2_size);
             break;
         case COAP_OPTION_BLOCK1:
             pkt->block1_num = coap_parse_int_option(cur_opt, opt_len);
@@ -756,19 +759,20 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
             pkt->block1_offset =
               (pkt->block1_num & ~0x0000000F) << (pkt->block1_num & 0x07);
             pkt->block1_num >>= 4;
-            LOG("Block1 [%lu%s (%u B/blk)]\n", (unsigned long)pkt->block1_num,
-              pkt->block1_more ? "+" : "", pkt->block1_size);
+            OC_LOG_DEBUG("Block1 [%lu%s (%u B/blk)]\n",
+                         (unsigned long)pkt->block1_num,
+                         pkt->block1_more ? "+" : "", pkt->block1_size);
             break;
         case COAP_OPTION_SIZE2:
             pkt->size2 = coap_parse_int_option(cur_opt, opt_len);
-            LOG("Size2 [%lu]\n", (unsigned long)pkt->size2);
+            OC_LOG_DEBUG("Size2 [%lu]\n", (unsigned long)pkt->size2);
             break;
         case COAP_OPTION_SIZE1:
             pkt->size1 = coap_parse_int_option(cur_opt, opt_len);
-            LOG("Size1 [%lu]\n", (unsigned long)pkt->size1);
+            OC_LOG_DEBUG("Size1 [%lu]\n", (unsigned long)pkt->size1);
             break;
         default:
-            LOG("unknown (%u)\n", opt_num);
+            OC_LOG_DEBUG("unknown (%u)\n", opt_num);
             /* check if critical (odd) */
             if (opt_num & 1) {
                 coap_error_message = "Unsupported critical option";
@@ -778,7 +782,6 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
         }
         cur_opt += opt_len;
     } /* for */
-    LOG("-Done parsing-------\n");
 
     return NO_ERROR;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/messaging/coap/coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.h b/net/oic/src/messaging/coap/coap.h
index 586310c..3dc0f49 100644
--- a/net/oic/src/messaging/coap/coap.h
+++ b/net/oic/src/messaging/coap/coap.h
@@ -166,6 +166,8 @@ typedef struct coap_packet {
 STATS_SECT_START(coap_stats)
     STATS_SECT_ENTRY(iframe)
     STATS_SECT_ENTRY(ierr)
+    STATS_SECT_ENTRY(itoobig)
+    STATS_SECT_ENTRY(imem)
     STATS_SECT_ENTRY(oframe)
     STATS_SECT_ENTRY(oerr)
 STATS_SECT_END
@@ -175,7 +177,7 @@ extern STATS_SECT_DECL(coap_stats) coap_stats;
 /* option format serialization */
 #define COAP_SERIALIZE_INT_OPT(pkt, m, number, field, text)             \
     if (IS_OPTION(pkt, number)) {                                       \
-        LOG(text " [%u]\n", (unsigned int)pkt->field);                  \
+        OC_LOG_DEBUG(" %s [%u]\n", text, (unsigned int)pkt->field);     \
         if (coap_append_int_opt(m, number, current_number, pkt->field)) { \
             goto err_mem;                                               \
         }                                                               \
@@ -183,10 +185,8 @@ extern STATS_SECT_DECL(coap_stats) coap_stats;
     }
 #define COAP_SERIALIZE_BYTE_OPT(pkt, m, number, field, text)            \
     if (IS_OPTION(pkt, number)) {                                       \
-        LOG(text " %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",          \
-          (unsigned int)pkt->field##_len, pkt->field[0], pkt->field[1], \
-          pkt->field[2], pkt->field[3], pkt->field[4], pkt->field[5],   \
-          pkt->field[6], pkt->field[7]); /* FIXME always prints 8 bytes */ \
+        OC_LOG_DEBUG(" %s %u ", text, pkt->field##_len);                \
+        OC_LOG_HEX(LOG_LEVEL_DEBUG, pkt->field, pkt->field##_len);      \
         if (coap_append_array_opt(m, number, current_number, pkt->field, \
                                   pkt->field##_len, '\0')) {            \
             goto err_mem;                                               \
@@ -195,7 +195,8 @@ extern STATS_SECT_DECL(coap_stats) coap_stats;
     }
 #define COAP_SERIALIZE_STRING_OPT(pkt, m, number, field, splitter, text) \
     if (IS_OPTION(pkt, number)) {                                       \
-        LOG(text " [%s]\n", pkt->field);                                \
+        OC_LOG_DEBUG(" %s", text);                                      \
+        OC_LOG_STR(LOG_LEVEL_DEBUG, pkt->field, pkt->field##_len);      \
         if (coap_append_array_opt(m, number, current_number,            \
                                   (uint8_t *)pkt->field,                \
                                   pkt->field##_len, splitter)) {        \
@@ -205,14 +206,16 @@ extern STATS_SECT_DECL(coap_stats) coap_stats;
     }
 #define COAP_SERIALIZE_BLOCK_OPT(pkt, m, number, field, text)           \
     if (IS_OPTION(pkt, number)) {                                       \
-        LOG(text " [%lu%s (%u B/blk)]\n", (unsigned long)pkt->field##_num, \
-          pkt->field##_more ? "+" : "", pkt->field##_size);             \
+        OC_LOG_DEBUG(" %s [%lu%s (%u B/blk)]\n", text,                  \
+                     (unsigned long)pkt->field##_num,                   \
+                     pkt->field##_more ? "+" : "", pkt->field##_size);  \
         uint32_t block = pkt->field##_num << 4;                         \
         if (pkt->field##_more) {                                        \
             block |= 0x8;                                               \
         }                                                               \
         block |= 0xF & coap_log_2(pkt->field##_size / 16);              \
-        LOG(text " encoded: 0x%lX\n", (unsigned long)block);            \
+        OC_LOG_DEBUG(" %s encoded: 0x%lX\n", text,                      \
+                     (unsigned long)block);                             \
         if (coap_append_int_opt(m, number, current_number, block)) {    \
             goto err_mem;                                               \
         }                                                               \

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index 0e95dae..f06097b 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -65,7 +65,7 @@ coap_receive(oc_message_t *msg)
 
     erbium_status_code = NO_ERROR;
 
-    LOG("\nCoAP Engine: received datalen=%u\n", (unsigned int) msg->length);
+    OC_LOG_INFO("CoAP: received datalen=%u\n", (unsigned int) msg->length);
 
     erbium_status_code = coap_parse_message(message, msg->data, msg->length,
                                            oc_endpoint_use_tcp(&msg->endpoint));
@@ -111,14 +111,7 @@ coap_receive(oc_message_t *msg)
             break;
         }
 
-#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_DEBUG
-        uint8_t uri[64];
-        memcpy(uri, message->uri_path, message->uri_path_len);
-        uri[message->uri_path_len] = '\0';
-
-        OC_LOG_DEBUG("  URL: %s\n", uri);
         OC_LOG_DEBUG("  Payload: %d bytes\n", message->payload_len);
-#endif
 
         /* use transaction buffer for response to confirmable request */
         transaction = coap_new_transaction(message->mid, &msg->endpoint);
@@ -150,9 +143,9 @@ coap_receive(oc_message_t *msg)
         }
         if (coap_get_header_block2(message, &block_num, NULL,
                                    &block_size, &block_offset)) {
-            LOG("\tBlockwise: block request %u (%u/%u) @ %u bytes\n",
-                (unsigned int) block_num, block_size,
-                COAP_MAX_BLOCK_SIZE, (unsigned int) block_offset);
+            OC_LOG_DEBUG(" Blockwise: block request %u (%u/%u) @ %u bytes\n",
+                         (unsigned int) block_num, block_size,
+                         COAP_MAX_BLOCK_SIZE, (unsigned int) block_offset);
             block_size = MIN(block_size, COAP_MAX_BLOCK_SIZE);
             new_offset = block_offset;
         }
@@ -174,7 +167,7 @@ coap_receive(oc_message_t *msg)
                 if (IS_OPTION(message, COAP_OPTION_BLOCK1) &&
                   response->code < BAD_REQUEST_4_00 &&
                   !IS_OPTION(response, COAP_OPTION_BLOCK1)) {
-                    LOG("\tBlock1 option NOT IMPLEMENTED\n");
+                    OC_LOG_ERROR(" Block1 option NOT IMPLEMENTED\n");
 
                     erbium_status_code = NOT_IMPLEMENTED_5_01;
                     coap_error_message = "NoBlock1Support";
@@ -187,13 +180,9 @@ coap_receive(oc_message_t *msg)
                      * unaware of blockwise transfer
                      */
                     if (new_offset == block_offset) {
-                        LOG("\tBlockwise: unaware resource with payload"
-                            " length %u/%u\n", response->payload_len,
-                                               block_size);
+                        OC_LOG_DEBUG(" Block: unaware resource %u/%u\n",
+                                     response->payload_len, block_size);
                         if (block_offset >= response->payload_len) {
-                            LOG("\t\t: block_offset >= "
-                                "response->payload_len\n");
-
                             response->code = BAD_OPTION_4_02;
                             coap_set_payload(response, "BlockOutOfScope", 15);
                             /* a const char str[] and sizeof(str)
@@ -210,8 +199,8 @@ coap_receive(oc_message_t *msg)
 
                         /* resource provides chunk-wise data */
                     } else {
-                        LOG("\tBlockwise: blockwise resource, new "
-                            "offset %d\n", (int) new_offset);
+                        OC_LOG_DEBUG(" Block: aware resource, off %d\n",
+                                     (int) new_offset);
                         coap_set_header_block2(response, block_num,
                                                new_offset != -1 ||
                                          response->payload_len > block_size,
@@ -225,9 +214,8 @@ coap_receive(oc_message_t *msg)
 
                     /* Resource requested Block2 transfer */
                 } else if (new_offset != 0) {
-                    LOG("\tBlockwise: no block option for blockwise "
-                        "resource, using block size %u\n",
-                        COAP_MAX_BLOCK_SIZE);
+                    OC_LOG_DEBUG(" block: no block option, using block sz %u\n",
+                                 COAP_MAX_BLOCK_SIZE);
 
                     coap_set_header_block2(response, 0, new_offset != -1,
                                            COAP_MAX_BLOCK_SIZE);
@@ -285,7 +273,7 @@ out:
             coap_send_transaction(transaction);
         }
     } else if (erbium_status_code == CLEAR_TRANSACTION) {
-        LOG("Clearing transaction for manual response\n");
+        OC_LOG_DEBUG(" Clearing transaction for manual response\n");
         /* used in server for separate response */
         coap_clear_transaction(transaction);
   }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
index 65bf85a..73d70e8 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -82,7 +82,7 @@ add_observer(oc_resource_t *resource, oc_endpoint_t *endpoint,
         o->obs_counter = observe_counter;
         o->resource = resource;
         resource->num_observers++;
-        LOG("Adding observer (%u/%u) for /%s [0x%02X%02X]\n",
+        OC_LOG_DEBUG("Adding observer (%u/%u) for /%s [0x%02X%02X]\n",
           coap_observer_pool.mp_num_blocks - coap_observer_pool.mp_num_free,
           coap_observer_pool.mp_num_blocks, o->url, o->token[0], o->token[1]);
         SLIST_INSERT_HEAD(&oc_observers, o, next);
@@ -96,8 +96,8 @@ add_observer(oc_resource_t *resource, oc_endpoint_t *endpoint,
 void
 coap_remove_observer(coap_observer_t *o)
 {
-    LOG("Removing observer for /%s [0x%02X%02X]\n", o->url, o->token[0],
-      o->token[1]);
+    OC_LOG_DEBUG("Removing observer for /%s [0x%02X%02X]\n",
+                 o->url, o->token[0], o->token[1]);
     SLIST_REMOVE(&oc_observers, o, coap_observer, next);
     os_memblock_put(&coap_observer_pool, o);
 }
@@ -108,9 +108,6 @@ coap_remove_observer_by_client(oc_endpoint_t *endpoint)
     int removed = 0;
     coap_observer_t *obs, *next;
 
-    LOG("Unregistering observers for client at: ");
-    LOGipaddr(*endpoint);
-
     obs = SLIST_FIRST(&oc_observers);
     while (obs) {
         next = SLIST_NEXT(obs, next);
@@ -121,7 +118,6 @@ coap_remove_observer_by_client(oc_endpoint_t *endpoint)
         }
         obs = next;
     }
-    LOG("Removed %d observers\n", removed);
     return removed;
 }
 /*---------------------------------------------------------------------------*/
@@ -131,8 +127,6 @@ coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,
 {
     int removed = 0;
     coap_observer_t *obs, *next;
-    LOG("Unregistering observers for request token 0x%02X%02X\n", token[0],
-      token[1]);
 
     obs = SLIST_FIRST(&oc_observers);
     while (obs) {
@@ -147,14 +141,12 @@ coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,
         }
         obs = next;
     }
-    LOG("Removed %d observers\n", removed);
     return removed;
 }
 /*---------------------------------------------------------------------------*/
 int
 coap_remove_observer_by_uri(oc_endpoint_t *endpoint, const char *uri)
 {
-    LOG("Unregistering observers for resource uri /%s", uri);
     int removed = 0;
     coap_observer_t *obs, *next;
 
@@ -169,7 +161,6 @@ coap_remove_observer_by_uri(oc_endpoint_t *endpoint, const char *uri)
         }
         obs = next;
     }
-    LOG("Removed %d observers\n", removed);
     return removed;
 }
 /*---------------------------------------------------------------------------*/
@@ -178,7 +169,6 @@ coap_remove_observer_by_mid(oc_endpoint_t *endpoint, uint16_t mid)
 {
     int removed = 0;
     coap_observer_t *obs, *next;
-    LOG("Unregistering observers for request MID %u\n", mid);
 
     obs = SLIST_FIRST(&oc_observers);
     while (obs) {
@@ -192,7 +182,6 @@ coap_remove_observer_by_mid(oc_endpoint_t *endpoint, uint16_t mid)
         }
         obs = next;
     }
-    LOG("Removed %d observers\n", removed);
     return removed;
 }
 /*---------------------------------------------------------------------------*/
@@ -206,7 +195,7 @@ coap_notify_observers(oc_resource_t *resource,
     int num_observers = 0;
     if (resource) {
         if (!resource->num_observers) {
-            LOG("coap_notify_observers: no observers; returning\n");
+            OC_LOG_DEBUG("coap_notify_observers: no observers left\n");
             return 0;
         }
         num_observers = resource->num_observers;
@@ -217,7 +206,7 @@ coap_notify_observers(oc_resource_t *resource,
     response.separate_response = 0;
     oc_response_buffer_t response_buffer;
     if (!response_buf && resource && (resource->properties & OC_PERIODIC)) {
-        LOG("coap_notify_observers: Issue GET request to resource\n");
+        OC_LOG_DEBUG("coap_notify_observers: Issue GET request to resource\n");
         /* performing GET on the resource */
         response_buffer.buffer = buffer;
         response_buffer.buffer_size = COAP_MAX_BLOCK_SIZE;
@@ -230,7 +219,7 @@ coap_notify_observers(oc_resource_t *resource,
         resource->get_handler(&request, resource->default_interface);
         response_buf = &response_buffer;
         if (response_buf->code == OC_IGNORE) {
-            LOG("coap_notify_observers: Resource ignored request\n");
+            OC_LOG_ERROR("coap_notify_observers: Resource ignored request\n");
             return num_observers;
         }
     }
@@ -255,13 +244,13 @@ coap_notify_observers(oc_resource_t *resource,
             coap_init_message(req, COAP_TYPE_NON, CONTENT_2_05, 0);
             memcpy(req->token, obs->token, obs->token_len);
             req->token_len = obs->token_len;
-            LOG("Resource is SLOW; creating separate response\n");
+            OC_LOG_DEBUG("Resource is SLOW; creating separate response\n");
             if (coap_separate_accept(req, response.separate_response,
                 &obs->endpoint, 0) == 1) {
                 response.separate_response->active = 1;
             }
         } else {
-            LOG("coap_notify_observers: notifying observer\n");
+            OC_LOG_DEBUG("coap_notify_observers: notifying observer\n");
             coap_transaction_t *transaction = NULL;
             if (response_buf && (transaction = coap_new_transaction(
                   coap_get_mid(), &obs->endpoint))) {
@@ -277,8 +266,8 @@ coap_notify_observers(oc_resource_t *resource,
 
                 notification->mid = transaction->mid;
                 if (obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0) {
-                    LOG("coap_observe_notify: forcing CON notification to "
-                      "check for client liveness\n");
+                    OC_LOG_DEBUG("coap_observe_notify: forcing CON "
+                                 "notification to check for client liveness\n");
                     notification->type = COAP_TYPE_CON;
                 }
                 coap_set_payload(notification, response_buf->buffer,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/messaging/coap/separate.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.c b/net/oic/src/messaging/coap/separate.c
index 7588866..650ed5b 100644
--- a/net/oic/src/messaging/coap/separate.c
+++ b/net/oic/src/messaging/coap/separate.c
@@ -93,7 +93,7 @@ coap_separate_accept(coap_packet_t *coap_req,
     erbium_status_code = CLEAR_TRANSACTION;
     /* send separate ACK for CON */
     if (coap_req->type == COAP_TYPE_CON) {
-        LOG("Sending ACK for separate response\n");
+        OC_LOG_DEBUG("Sending ACK for separate response\n");
         coap_packet_t ack[1];
         /* ACK with empty code (0) */
         coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.c b/net/oic/src/messaging/coap/transactions.c
index a1ffe6c..af16417 100644
--- a/net/oic/src/messaging/coap/transactions.c
+++ b/net/oic/src/messaging/coap/transactions.c
@@ -74,7 +74,6 @@ coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
     if (t) {
         m = oc_allocate_mbuf(endpoint);
         if (m) {
-            LOG("Created new transaction %d\n", mid);
             t->mid = mid;
             t->retrans_counter = 0;
             t->m = m;
@@ -96,25 +95,25 @@ coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
 void
 coap_send_transaction(coap_transaction_t *t)
 {
-    LOG("Sending transaction %u\n", t->mid);
     bool confirmable = false;
 
     confirmable = (COAP_TYPE_CON == t->type) ? true : false;
 
+    OC_LOG_DEBUG("Sending transaction %u\n", t->mid);
+
     if (confirmable) {
         if (t->retrans_counter < COAP_MAX_RETRANSMIT) {
             /* not timed out yet */
-            LOG("Keeping transaction %u\n", t->mid);
-
             if (t->retrans_counter == 0) {
                 t->retrans_tmo =
                   COAP_RESPONSE_TIMEOUT_TICKS +
                   (oc_random_rand() %
                     (oc_clock_time_t)COAP_RESPONSE_TIMEOUT_BACKOFF_MASK);
-                LOG("Initial interval " OC_CLK_FMT "\n", t->retrans_tmo);
+                OC_LOG_DEBUG("Initial interval " OC_CLK_FMT "\n",
+                             t->retrans_tmo);
             } else {
                 t->retrans_tmo <<= 1; /* double */
-                LOG("Doubled " OC_CLK_FMT "\n", t->retrans_tmo);
+                OC_LOG_DEBUG("Doubled " OC_CLK_FMT "\n", t->retrans_tmo);
             }
 
             os_callout_reset(&t->retrans_timer, t->retrans_tmo);
@@ -124,10 +123,9 @@ coap_send_transaction(coap_transaction_t *t)
             t = NULL;
         } else {
             /* timed out */
-            LOG("Timeout\n");
+            OC_LOG_DEBUG("Timeout\n");
 
 #ifdef OC_SERVER
-            LOG("timeout.. so removing observers\n");
             /* handle observers */
             coap_remove_observer_by_client(OC_MBUF_ENDPOINT(t->m));
 #endif /* OC_SERVER */
@@ -158,8 +156,6 @@ coap_clear_transaction(coap_transaction_t *t)
     struct coap_transaction *tmp;
 
     if (t) {
-        LOG("Freeing transaction %u: 0x%x\n", t->mid, (unsigned)t);
-
         os_callout_stop(&t->retrans_timer);
         os_mbuf_free_chain(t->m);
 
@@ -183,7 +179,6 @@ coap_get_transaction_by_mid(uint16_t mid)
 
     SLIST_FOREACH(t, &oc_transaction_list, next) {
         if (t->mid == mid) {
-            LOG("Found transaction for MID %u: 0x%x\n", t->mid, (unsigned)t);
             return t;
         }
     }
@@ -195,7 +190,7 @@ coap_transaction_retrans(struct os_event *ev)
 {
     coap_transaction_t *t = ev->ev_arg;
     ++(t->retrans_counter);
-    LOG("Retransmitting %u (%u)\n", t->mid, t->retrans_counter);
+    OC_LOG_DEBUG("Retransmitting %u (%u)\n", t->mid, t->retrans_counter);
     coap_send_transaction(t);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
index 79b7f93..22edda3 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -92,7 +92,7 @@ oc_send_buffer(struct os_mbuf *m)
         break;
 #endif
     default:
-        ERROR("Unknown transport option %u\n", oe->flags);
+        OC_LOG_ERROR("Unknown transport option %u\n", oe->flags);
         os_mbuf_free_chain(m);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 7bfa452..14128f2 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -159,12 +159,9 @@ oc_attempt_rx_gatt(void)
     struct oc_endpoint *oe;
     uint16_t conn_handle;
 
-    LOG("oc_gatt attempt rx\n");
-
     /* get an mbuf from the queue */
     n = os_mqueue_get(&oc_ble_coap_mq);
     if (NULL == n) {
-        ERROR("oc_gatt Woke for receive but found no mbufs\n");
         return NULL;
     }
 
@@ -177,7 +174,7 @@ oc_attempt_rx_gatt(void)
     rc = os_mbuf_copydata(n, pkt->omp_len - sizeof(conn_handle),
                           sizeof(conn_handle), &conn_handle);
     if (rc != 0) {
-        ERROR("oc_gatt Failed to retrieve conn_handle from mbuf\n");
+        OC_LOG_ERROR("oc_gatt_rx: Failed to get conn_handle from mbuf\n");
         goto rx_attempt_err;
     }
 
@@ -186,7 +183,7 @@ oc_attempt_rx_gatt(void)
 
     m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
     if (!m) {
-        ERROR("oc_gatt Could not allocate OC message buffer\n");
+        OC_LOG_ERROR("oc_gatt_rx: Could not allocate mbuf\n");
         goto rx_attempt_err;
     }
     OS_MBUF_PKTHDR(m)->omp_len = pkt->omp_len;
@@ -197,8 +194,6 @@ oc_attempt_rx_gatt(void)
     oe->flags = GATT;
     oe->bt_addr.conn_handle = conn_handle;
 
-    LOG("oc_gatt rx %x-%u\n", (unsigned)pkt, pkt->omp_len);
-
     return m;
 
     /* add the addr info to the message */
@@ -246,7 +241,7 @@ oc_ble_reass(struct os_mbuf *om1)
     assert(pkt1);
     oe1 = OC_MBUF_ENDPOINT(om1);
 
-    LOG("oc_gatt rx seg %d-%x-%u\n", oe1->bt_addr.conn_handle,
+    OC_LOG_DEBUG("oc_gatt rx seg %d-%x-%u\n", oe1->bt_addr.conn_handle,
       (unsigned)pkt1, pkt1->omp_len);
 
     OS_ENTER_CRITICAL(sr);
@@ -288,7 +283,7 @@ oc_ble_reass(struct os_mbuf *om1)
 void
 oc_ble_coap_conn_new(uint16_t conn_handle)
 {
-    LOG("oc_gatt newconn %x\n", conn_handle);
+    OC_LOG_DEBUG("oc_gatt newconn %x\n", conn_handle);
 }
 
 void
@@ -299,7 +294,7 @@ oc_ble_coap_conn_del(uint16_t conn_handle)
     struct oc_endpoint *oe;
     int sr;
 
-    LOG("oc_gatt endconn %x\n", conn_handle);
+    OC_LOG_DEBUG("oc_gatt endconn %x\n", conn_handle);
     OS_ENTER_CRITICAL(sr);
     STAILQ_FOREACH(pkt, &oc_ble_reass_q, omp_next) {
         m = OS_MBUF_PKTHDR_TO_MBUF(pkt);
@@ -396,7 +391,7 @@ oc_send_buffer_gatt(struct os_mbuf *m)
     conn_handle = oe->bt_addr.conn_handle;
 
 #if (MYNEWT_VAL(OC_CLIENT) == 1)
-    ERROR("oc_gatt send not supported on client");
+    OC_LOG_ERROR("oc_gatt send not supported on client");
 #endif
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
@@ -424,15 +419,4 @@ oc_send_buffer_gatt(struct os_mbuf *m)
 #endif
 }
 
-void
-oc_send_buffer_gatt_mcast(oc_message_t *message)
-{
-#if (MYNEWT_VAL(OC_CLIENT) == 1)
-    ERROR("oc_gatt send not supported on client");
-#elif (MYNEWT_VAL(OC_SERVER) == 1)
-    oc_message_unref(message);
-    ERROR("oc_gatt no multicast support for server only system \n");
-#endif
-}
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 6f16d96..634417a 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -69,9 +69,6 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
     struct os_mbuf *n;
     int rc;
 
-    LOG("oc_transport_ip attempt send buffer %u\n",
-      OS_MBUF_PKTHDR(m)->omp_len);
-
     oe = OC_MBUF_ENDPOINT(m);
 
     to.msin6_len = sizeof(to);
@@ -106,8 +103,8 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
             to.msin6_scope_id = itf2.mif_idx;
             rc = mn_sendto(ucast, n, (struct mn_sockaddr *) &to);
             if (rc != 0) {
-                ERROR("Failed sending buffer %u on itf %d\n",
-                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+                OC_LOG_ERROR("Failed to send buffer %u on itf %d\n",
+                             OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
                 os_mbuf_free_chain(n);
             }
         }
@@ -115,16 +112,16 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
             to.msin6_scope_id = itf2.mif_idx;
             rc = mn_sendto(ucast, m, (struct mn_sockaddr *) &to);
             if (rc != 0) {
-                ERROR("Failed sending buffer %u on itf %d\n",
-                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+                OC_LOG_ERROR("Failed sending buffer %u on itf %d\n",
+                             OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
                 os_mbuf_free_chain(m);
             }
         }
     } else {
         rc = mn_sendto(ucast, m, (struct mn_sockaddr *) &to);
         if (rc != 0) {
-            ERROR("Failed sending buffer %u on itf %d\n",
-                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+            OC_LOG_ERROR("Failed to send buffer %u on itf %d\n",
+                         OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
             os_mbuf_free_chain(m);
         }
     }
@@ -153,8 +150,6 @@ oc_attempt_rx_ip_sock(struct mn_socket *rxsock)
     struct oc_endpoint *oe;
     struct mn_sockaddr_in6 from;
 
-    LOG("oc_transport_ip attempt rx from 0x%x\n", (unsigned)rxsock);
-
     rc = mn_recvfrom(rxsock, &n, (struct mn_sockaddr *) &from);
     if (rc != 0) {
         return NULL;
@@ -163,7 +158,7 @@ oc_attempt_rx_ip_sock(struct mn_socket *rxsock)
 
     m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
     if (!m) {
-        ERROR("Could not allocate OC message buffer\n");
+        OC_LOG_ERROR("Could not allocate RX buffer\n");
         goto rx_attempt_err;
     }
     OS_MBUF_PKTHDR(m)->omp_len = OS_MBUF_PKTHDR(n)->omp_len;
@@ -171,17 +166,12 @@ oc_attempt_rx_ip_sock(struct mn_socket *rxsock)
 
     oe = OC_MBUF_ENDPOINT(m);
 
-    LOG("rx from 0x%x 0x%x-%u\n", (unsigned)rxsock, (unsigned)m,
-                                  OS_MBUF_PKTHDR(m)->omp_len);
-
     oe->flags = IP;
     memcpy(&oe->ipv6_addr.address, &from.msin6_addr,
              sizeof(oe->ipv6_addr.address));
     oe->ipv6_addr.scope = from.msin6_scope_id;
     oe->ipv6_addr.port = ntohs(from.msin6_port);
 
-    LOG("Successfully rx from 0x%x\n", (unsigned)rxsock);
-
     return m;
 
     /* add the addr info to the message */
@@ -220,8 +210,6 @@ oc_socks_readable(void *cb_arg, int err)
 void
 oc_connectivity_shutdown_ip(void)
 {
-    LOG("OC shutdown IP\n");
-
     if (ucast) {
         mn_close(ucast);
     }
@@ -251,12 +239,11 @@ oc_connectivity_init_ip(void)
     struct mn_sockaddr_in6 sin;
     struct mn_itf itf;
 
-    LOG("OC transport init IP\n");
     memset(&itf, 0, sizeof(itf));
 
     rc = mn_socket(&ucast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
     if ( rc != 0 || !ucast ) {
-        ERROR("Could not create oc unicast socket\n");
+        OC_LOG_ERROR("Could not create oc unicast socket\n");
         return rc;
     }
     mn_socket_set_cbs(ucast, ucast, &oc_sock_cbs);
@@ -265,7 +252,7 @@ oc_connectivity_init_ip(void)
     rc = mn_socket(&mcast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
     if ( rc != 0 || !mcast ) {
         mn_close(ucast);
-        ERROR("Could not create oc multicast socket\n");
+        OC_LOG_ERROR("Could not create oc multicast socket\n");
         return rc;
     }
     mn_socket_set_cbs(mcast, mcast, &oc_sock_cbs);
@@ -279,7 +266,7 @@ oc_connectivity_init_ip(void)
 
     rc = mn_bind(ucast, (struct mn_sockaddr *)&sin);
     if (rc != 0) {
-        ERROR("Could not bind oc unicast socket\n");
+        OC_LOG_ERROR("Could not bind oc unicast socket\n");
         goto oc_connectivity_init_err;
     }
 
@@ -303,17 +290,16 @@ oc_connectivity_init_ip(void)
 
         rc = mn_setsockopt(mcast, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &join);
         if (rc != 0) {
-            ERROR("Could not join multicast group on %s\n", itf.mif_name);
             continue;
         }
 
-        LOG("Joined Coap mcast group on %s\n", itf.mif_name);
+        OC_LOG_DEBUG("Joined Coap mcast group on %s\n", itf.mif_name);
     }
 
     sin.msin6_port = htons(COAP_PORT_UNSECURED);
     rc = mn_bind(mcast, (struct mn_sockaddr *)&sin);
     if (rc != 0) {
-        ERROR("Could not bind oc multicast socket\n");
+        OC_LOG_ERROR("Could not bind oc multicast socket\n");
         goto oc_connectivity_init_err;
     }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index 224270f..130e26d 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -83,11 +83,9 @@ err:
 void
 oc_send_buffer_serial(struct os_mbuf *m)
 {
-    LOG("oc_transport_serial: send buffer %u\n", OS_MBUF_PKTHDR(m)->omp_len);
-
     /* send over the shell output */
     if (shell_nlip_output(m)) {
-        ERROR("oc_transport_serial: nlip output failed\n");
+        OC_LOG_ERROR("oc_transport_serial: nlip output failed\n");
     }
 }
 
@@ -98,18 +96,15 @@ oc_attempt_rx_serial(void)
     struct os_mbuf *n;
     struct oc_endpoint *oe;
 
-    LOG("oc_transport_serial attempt rx\n");
-
     /* get an mbuf from the queue */
     n = os_mqueue_get(&oc_serial_mqueue);
     if (NULL == n) {
-        ERROR("oc_transport_serial: Woke for for receive but found no mbufs\n");
         return NULL;
     }
 
     m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
     if (!m) {
-        ERROR("Could not allocate OC message buffer\n");
+        OC_LOG_ERROR("Could not allocate OC message buffer\n");
         goto rx_attempt_err;
     }
     OS_MBUF_PKTHDR(m)->omp_len = OS_MBUF_PKTHDR(n)->omp_len;
@@ -118,9 +113,6 @@ oc_attempt_rx_serial(void)
     oe = OC_MBUF_ENDPOINT(m);
     oe->flags = SERIAL;
 
-    LOG("oc_transport_serial rx 0x%x-%u\n",
-        (unsigned)n, OS_MBUF_PKTHDR(n)->omp_len);
-
     return m;
 
 rx_attempt_err:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78fc1792/net/oic/src/port/oc_assert.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_assert.h b/net/oic/src/port/oc_assert.h
index 6361c66..369a3d9 100644
--- a/net/oic/src/port/oc_assert.h
+++ b/net/oic/src/port/oc_assert.h
@@ -17,31 +17,19 @@
 #ifndef OC_ASSERT_H
 #define OC_ASSERT_H
 
-#include "oc_log.h"
+#include <assert.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#ifdef __linux__
-#include <stdlib.h>
-#define abort_impl() abort()
-#else
-void abort_impl(void);
-#endif
-
-#define oc_abort(msg)                                                          \
-  do {                                                                         \
-    LOG("\n%s:%d:%s: error: %s\nAbort.\n", __FILE__, __LINE__, __func__, msg); \
-    abort_impl();                                                              \
+#define oc_abort(msg)                                                   \
+    do {                                                                \
+      OC_LOG_ERROR("error: %s\nAbort.\n", msg);                         \
+      assert(0);                                                        \
   } while (0)
 
-#define oc_assert(cond)                                                        \
-  do {                                                                         \
-    if (!(cond)) {                                                             \
-      oc_abort("Assertion (" #cond ") failed.");                               \
-    }                                                                          \
-  } while (0)
+#define oc_assert(cond) assert(cond)
 
 #ifdef __cplusplus
 }


Mime
View raw message