Skip to content

Commit

Permalink
Merge pull request #125 from cgzones/logging
Browse files Browse the repository at this point in the history
Log reason for reconnect and underlying connection protocol
  • Loading branch information
ssahani authored Oct 21, 2024
2 parents 8ec7067 + 934a09f commit e8ddb8d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/netlog/netlog-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ static int manager_journal_monitor_listen(Manager *m) {
if (r < 0)
return r;

sd_journal_set_data_threshold(m->journal, 0);
r = sd_journal_set_data_threshold(m->journal, 0);
if (r < 0)
log_warning_errno(r, "Failed to set journal data field size threshold");

m->journal_watch_fd = sd_journal_get_fd(m->journal);
if (m->journal_watch_fd < 0)
Expand Down
14 changes: 10 additions & 4 deletions src/netlog/netlog-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ int manager_push_to_network(Manager *m,
switch (m->protocol) {
case SYSLOG_TRANSMISSION_PROTOCOL_DTLS:
if (!m->dtls->connected) {
log_debug("DTLS not connected, performing reconnect");
r = manager_connect(m);
if (r < 0)
return r;
Expand All @@ -95,13 +96,15 @@ int manager_push_to_network(Manager *m,
break;
case SYSLOG_TRANSMISSION_PROTOCOL_TLS:
if (!m->tls->connected) {
log_debug("TLS not connected, performing reconnect");
r = manager_connect(m);
if (r < 0)
return r;
}
break;
default:
if (!m->connected) {
log_debug("%s not connected, performing reconnect", protocol_to_string(m->protocol));
r = manager_connect(m);
if (r < 0)
return r;
Expand Down Expand Up @@ -136,6 +139,7 @@ void manager_close_network_socket(Manager *m) {
int manager_network_connect_socket(Manager *m) {
_cleanup_free_ char *pretty = NULL;
union sockaddr_union sa;
const char *protocol;
socklen_t salen;
int r;

Expand Down Expand Up @@ -167,16 +171,18 @@ int manager_network_connect_socket(Manager *m) {
if (r < 0)
return r;

log_debug("Connecting to remote server: '%s'", pretty);
protocol = protocol_to_string(m->protocol);

log_debug("Connecting to remote server: '%s/%s'", pretty, protocol);

r = connect(m->socket, &m->address.sockaddr.sa, salen);
if (r < 0 && errno != EINPROGRESS)
return log_error_errno(errno, "Failed to connect to remote server='%s': %m", pretty);
return log_error_errno(errno, "Failed to connect to remote server='%s/%s': %m", pretty, protocol);

if (errno != EINPROGRESS)
log_debug("Connected to remote server: '%s'", pretty);
log_debug("Connected to remote server: '%s/%s'", pretty, protocol);
else
log_debug("Connection in progress to remote server: '%s'", pretty);
log_debug("Connection in progress to remote server: '%s/%s'", pretty, protocol);

return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions src/netlog/netlog-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ int protocol_send(Manager *m, struct iovec *iovec, unsigned n_iovec) {
case SYSLOG_TRANSMISSION_PROTOCOL_DTLS:
r = dtls_datagram_writev(m->dtls, iovec, n_iovec);
if (r < 0 && r != -EAGAIN) {
log_debug_errno(r, "Failed to send via DTLS, performing reconnect: %m");
manager_connect(m);
return r;
}
break;
case SYSLOG_TRANSMISSION_PROTOCOL_TLS:
r = tls_stream_writev(m->tls, iovec, n_iovec);
if (r < 0 && r != -EAGAIN) {
log_debug_errno(r, "Failed to send via TLS, performing reconnect: %m");
manager_connect(m);
return r;
}
break;
default:
r = network_send(m, iovec, n_iovec);
if (r < 0 && r != -EAGAIN) {
log_debug_errno(r, "Failed to send via %s, performing reconnect: %m", protocol_to_string(m->protocol));
manager_connect(m);
return r;
}
Expand Down

0 comments on commit e8ddb8d

Please sign in to comment.