Skip to content

Commit

Permalink
log
Browse files Browse the repository at this point in the history
Signed-off-by: jaylin <[email protected]>
  • Loading branch information
JaylinYu committed Aug 30, 2024
1 parent 10de9e0 commit bc132cd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
3 changes: 3 additions & 0 deletions demo/paho/paho.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
19 changes: 18 additions & 1 deletion src/core/dialer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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));
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 *
Expand Down
2 changes: 2 additions & 0 deletions src/mqtt/transport/tcp/mqtt_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions src/platform/posix/posix_tcpconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ 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:
#endif
#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;
}
}
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sp/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/supplemental/mqtt/mqtt_nano_paho.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bc132cd

Please sign in to comment.