diff --git a/demo/paho/paho.c b/demo/paho/paho.c index 2a944ca4..c5c6610a 100644 --- a/demo/paho/paho.c +++ b/demo/paho/paho.c @@ -133,6 +133,9 @@ int main(int argc, char* argv[]) int rc; int ch; + // nng_log_set_logger(nng_system_logger); + nng_log_set_logger(nng_stderr_logger); + nng_log_set_level(NNG_LOG_DEBUG); if ((rc = MQTTAsync_create(&client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_NONE, NULL)) != MQTTASYNC_SUCCESS) { diff --git a/src/core/dialer.c b/src/core/dialer.c index 50690a20..9476436d 100644 --- a/src/core/dialer.c +++ b/src/core/dialer.c @@ -276,6 +276,10 @@ nni_dialer_create(nni_dialer **dp, nni_sock *s, const char *url_str) nni_stat_unregister(&d->st_root); #endif nni_dialer_destroy(d); + nng_log_warn("NanoSDK-CONN-FAIL", + "Fail to create the dialer of socket<%u> to %s: %s", + nni_sock_id(d->d_sock), d->d_url->u_rawurl, + nng_strerror(rv)); return (rv); } @@ -342,6 +346,8 @@ nni_dialer_close(nni_dialer *d) nni_dialer_rele(d); return; } + nng_log_debug("NanoSDK-Dialer", + "Dialer to %s is being closed", d->d_url->u_rawurl); d->d_closed = true; nni_id_remove(&dialers, d->d_id); nni_mtx_unlock(&dialers_lk); @@ -358,6 +364,9 @@ dialer_timer_cb(void *arg) nni_dialer *d = arg; if (nni_aio_result(&d->d_tmo_aio) == 0) { + nng_log_info("NanoSDK-Timer", + "socket<%u> to %s is reconnecting ...", + nni_sock_id(d->d_sock), d->d_url->u_rawurl); dialer_connect_start(d); } } @@ -385,11 +394,15 @@ dialer_connect_cb(void *arg) case NNG_ECLOSED: // No further action. case NNG_ECANCELED: // No further action. nni_dialer_bump_error(d, rv); + nng_log_warn("NanoSDK-CONN-FAIL", + "socket<%u> to %s is being closed: %s", + nni_sock_id(d->d_sock), d->d_url->u_rawurl, + nng_strerror(rv)); break; case NNG_ECONNREFUSED: case NNG_ETIMEDOUT: default: - nng_log_warn("NNG-CONN-FAIL", + nng_log_warn("NanoSDK-CONN-FAIL", "Failed connecting socket<%u> to %s: %s", nni_sock_id(d->d_sock), d->d_url->u_rawurl, nng_strerror(rv)); @@ -410,6 +423,8 @@ dialer_connect_cb(void *arg) static void dialer_connect_start(nni_dialer *d) { + nng_log_info("NanoSDK-DIAL", "Starting Connecting for socket<%u> on %s", + nni_sock_id(d->d_sock), d->d_url->u_rawurl); d->d_ops.d_connect(d->d_data, &d->d_con_aio); } @@ -456,6 +471,8 @@ nni_dialer_stop(nni_dialer *d) nni_aio_stop(&d->d_tmo_aio); nni_aio_stop(&d->d_con_aio); d->d_ops.d_close(d->d_data); + nng_log_info("NanoSDK-DIAL", "Stopping dialer for socket<%u> on %s", + nni_sock_id(d->d_sock), d->d_url->u_rawurl); } nni_sock * diff --git a/src/mqtt/transport/tcp/mqtt_tcp.c b/src/mqtt/transport/tcp/mqtt_tcp.c index 9bee27fc..43aa93e2 100644 --- a/src/mqtt/transport/tcp/mqtt_tcp.c +++ b/src/mqtt/transport/tcp/mqtt_tcp.c @@ -1535,6 +1535,8 @@ mqtt_tcptran_ep_connect(void *arg, nni_aio *aio) ep->backoff = ep->backoff > ep->backoff_max ? (nni_duration) (nni_random() % 1000) : ep->backoff; + nng_log_debug("NanoSDK-Transport", + "wait backoff time : %ld ms to start reconnect ... ", ep->backoff); nni_msleep(ep->backoff); } else { ep->backoff = nni_random()%2000; diff --git a/src/platform/posix/posix_tcpconn.c b/src/platform/posix/posix_tcpconn.c index ff8031ff..cf7fadfc 100644 --- a/src/platform/posix/posix_tcpconn.c +++ b/src/platform/posix/posix_tcpconn.c @@ -71,6 +71,8 @@ tcp_dowrite(nni_tcp_conn *c) case EINTR: continue; case EAGAIN: + nng_log_info("NanoSDK-POSIX-TCP", + "Socket %d is congested %d",fd, nni_plat_errno(errno)); #ifdef EWOULDBLOCK #if EWOULDBLOCK != EAGAIN case EWOULDBLOCK: @@ -78,9 +80,10 @@ tcp_dowrite(nni_tcp_conn *c) #endif return; default: + nng_log_info("NanoSDK-POSIX-TCP", + "sendmsg to Socket %d fail %d",fd, nni_plat_errno(errno)); nni_aio_list_remove(aio); - nni_aio_finish_error( - aio, nni_plat_errno(errno)); + nni_aio_finish_error(aio, nni_plat_errno(errno)); return; } } @@ -133,8 +136,12 @@ tcp_doread(nni_tcp_conn *c) case EINTR: continue; case EAGAIN: + nng_log_debug("NanoSDK-POSIX-TCP", + "Reading Socket %d return EAGAIN %d",fd, nni_plat_errno(errno)); return; default: + nng_log_info("NanoSDK-POSIX-TCP", + "readv of Socket %d fail %d",fd, nni_plat_errno(errno)); nni_aio_list_remove(aio); nni_aio_finish_error( aio, nni_plat_errno(errno)); @@ -145,6 +152,8 @@ tcp_doread(nni_tcp_conn *c) if (n == 0) { // No bytes indicates a closed descriptor. // This implicitly completes this (all!) aio. + nng_log_info("NanoSDK-POSIX-TCP", + "Reading Socket %d hits EOF",fd); nni_aio_list_remove(aio); nni_aio_finish_error(aio, NNG_ECONNSHUT); continue; diff --git a/src/sp/transport.c b/src/sp/transport.c index 8939438d..a6f09a69 100644 --- a/src/sp/transport.c +++ b/src/sp/transport.c @@ -25,7 +25,7 @@ nni_sp_tran_register(nni_sp_tran *tran) if (!nni_list_node_active(&tran->tran_link)) { tran->tran_init(); nni_list_append(&sp_tran_list, tran); - nng_log_info( + nng_log_debug( "NanoSDK-TRAN", "Registered transport: %s", tran->tran_scheme); } nni_rwlock_unlock(&sp_tran_lk); diff --git a/src/supplemental/mqtt/mqtt_nano_paho.c b/src/supplemental/mqtt/mqtt_nano_paho.c index eba96fb5..39e8a5e6 100644 --- a/src/supplemental/mqtt/mqtt_nano_paho.c +++ b/src/supplemental/mqtt/mqtt_nano_paho.c @@ -537,7 +537,7 @@ connect_cb(nng_pipe p, nng_pipe_ev ev, void *arg) // get property for MQTT V5 // property *prop; // nng_pipe_get_ptr(p, NNG_OPT_MQTT_CONNECT_PROPERTY, &prop); - nng_log_warn("Connected!", "This is also fine"); + nng_log_warn("NanoSDK-Internal!", "Pipe is Connected"); if (reason == MQTTREASONCODE_SUCCESS) { m->shouldBeConnected = 1; if (m->connect.onSuccess) {