Skip to content

Commit

Permalink
app: logging improvements
Browse files Browse the repository at this point in the history
Signed-off-by: hexian000 <[email protected]>
  • Loading branch information
hexian000 committed Dec 31, 2023
1 parent 4fa0509 commit 15abd17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,15 @@ int main(int argc, char **argv)
}

/* start event loop */
LOGN_F("%s start", runmode_str(conf->mode));
ev_run(loop, 0);

server_stop(s);
server_free(s);
LOGN_F("%s shutdown", runmode_str(conf->mode));
LOGN_F("%s shutdown gracefully", runmode_str(conf->mode));
ev_loop_destroy(loop);
conf_free(conf);

LOGI("program terminated normally.");
LOGD("program terminated normally");
return EXIT_SUCCESS;
}

Expand Down
10 changes: 5 additions & 5 deletions src/obfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,6 @@ static bool obfs_bind(struct obfs *restrict obfs, const struct sockaddr *sa)
const int err = errno;
LOGW_F("cap bind: %s", strerror(err));
}
if (LOGLEVEL(DEBUG)) {
char addr_str[64];
format_sa(sa, addr_str, sizeof(addr_str));
LOG_F(DEBUG, "obfs: cap bind %s", addr_str);
}
struct sock_filter filter[32];
struct sock_fprog fprog = {
.filter = filter,
Expand All @@ -421,6 +416,11 @@ static bool obfs_bind(struct obfs *restrict obfs, const struct sockaddr *sa)
const int err = errno;
LOGW_F("cap filter: %s", strerror(err));
}
if (LOGLEVEL(NOTICE)) {
char addr_str[64];
format_sa(sa, addr_str, sizeof(addr_str));
LOG_F(NOTICE, "obfs: bind %s", addr_str);
}
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ tcp_listen(const struct config *restrict conf, const struct sockaddr *sa)
/* Bind socket to address */
if (bind(fd, sa, getsocklen(sa)) != 0) {
const int err = errno;
LOGE_F("bind error: %s", strerror(err));
LOGE_F("tcp bind: %s", strerror(err));
CLOSE_FD(fd);
return -1;
}
/* Start listening on the socket */
if (listen(fd, SOMAXCONN)) {
const int err = errno;
LOGE_F("listen error: %s", strerror(err));
LOGE_F("tcp listen: %s", strerror(err));
CLOSE_FD(fd);
return -1;
}
Expand Down Expand Up @@ -90,10 +90,10 @@ static bool listener_start(struct server *restrict s)
w_accept->data = s;
ev_io_start(s->loop, w_accept);
l->fd = fd;
if (LOGLEVEL(INFO)) {
if (LOGLEVEL(NOTICE)) {
char addr_str[64];
format_sa(&addr.sa, addr_str, sizeof(addr_str));
LOG_F(INFO, "listen at: %s", addr_str);
LOG_F(NOTICE, "listen at %s", addr_str);
}
}

Expand All @@ -112,10 +112,10 @@ static bool listener_start(struct server *restrict s)
w_accept->data = s;
ev_io_start(s->loop, w_accept);
l->fd_http = fd;
if (LOGLEVEL(INFO)) {
if (LOGLEVEL(NOTICE)) {
char addr_str[64];
format_sa(&addr.sa, addr_str, sizeof(addr_str));
LOG_F(INFO, "http listen at: %s", addr_str);
LOG_F(NOTICE, "http listen at %s", addr_str);
}
}

Expand Down

0 comments on commit 15abd17

Please sign in to comment.