Skip to content

Commit d7a78ba

Browse files
authored
[dhcp4relay] Migrate syslog() to SWSS_LOG macros for runtime log-level control (#110)
dhcp4relay used raw syslog() calls throughout, which meant every log message regardless of level was unconditionally written to syslog with no way to suppress verbose output at runtime. Under sustained DHCP traffic the relay generates several hundred log lines per second, saturating rsyslog rate limits and causing syslog to rotate every ~14 minutes, burying real errors. This commit integrates swss::Logger so that log levels can be controlled at runtime via swssloglevel without restarting the daemon. Changes ------- - main.cpp: add swss::Logger::linkToDbNative("dhcp4relay") to register with LOGLEVEL_DB at startup (default level: NOTICE). - dhcp4relay.h: replace #include <syslog.h> with #include "logger.h". All .cpp files that include dhcp4relay.h (directly or transitively via dhcp4relay_mgr.h / dhcp4relay_stats.h) pick up logger.h through the existing include chain; no per-file change needed. - dhcp4_sender.cpp: replace #include <syslog.h> with #include "logger.h". - dhcp4relay.cpp, dhcp4relay_mgr.cpp, dhcp4relay_stats.cpp, dhcp4_sender.cpp, main.cpp: replace all 131 syslog() calls with the equivalent SWSS_LOG_* macros: LOG_ERR -> SWSS_LOG_ERROR LOG_WARNING -> SWSS_LOG_WARN LOG_NOTICE -> SWSS_LOG_NOTICE LOG_INFO -> SWSS_LOG_INFO LOG_DEBUG -> SWSS_LOG_DEBUG LOG_ALERT -> SWSS_LOG_NOTICE (signal_callback: receiving SIGTERM is normal operational behavior) - Remove trailing \n from all format strings; SWSS_LOG adds its own. Log level control after this change ------------------------------------ swssloglevel -c dhcp4relay -l NOTICE # production default swssloglevel -c dhcp4relay -l INFO # verbose operation swssloglevel -c dhcp4relay -l DEBUG # full per-packet tracing No functional change to relay behavior. Signed-off-by: Shivashankar CR <shivashankar.c.r@gmail.com>
1 parent 7316417 commit d7a78ba

6 files changed

Lines changed: 140 additions & 149 deletions

File tree

dhcp4relay/src/dhcp4_sender.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <arpa/inet.h>
44
#include <errno.h>
5-
#include <syslog.h>
5+
#include "logger.h"
66

77
#include <cstring>
88

@@ -63,14 +63,14 @@ bool send_udp(int sock, uint8_t *buffer, struct sockaddr_in target, uint32_t len
6363
if (sendmsg(sock, &msg, 0) == -1) {
6464
char server_addr[INET_ADDRSTRLEN];
6565
inet_ntop(AF_INET, &(target.sin_addr), server_addr, INET_ADDRSTRLEN);
66-
syslog(LOG_ERR, "sendmsg: Failed to send to target address: %s, error: %s\n", server_addr, strerror(errno));
66+
SWSS_LOG_ERROR("sendmsg: Failed to send to target address: %s, error: %s", server_addr, strerror(errno));
6767
return false;
6868
}
6969
} else {
7070
if (sendto(sock, buffer, len, 0, (const struct sockaddr *)&target, sizeof(target)) == -1) {
7171
char server_addr[INET_ADDRSTRLEN];
7272
inet_ntop(AF_INET, &(target.sin_addr), server_addr, INET_ADDRSTRLEN);
73-
syslog(LOG_ERR, "sendto: Failed to send to target address: %s, error: %s\n", server_addr, strerror(errno));
73+
SWSS_LOG_ERROR("sendto: Failed to send to target address: %s, error: %s", server_addr, strerror(errno));
7474
return false;
7575
}
7676
}

0 commit comments

Comments
 (0)