Commit d7a78ba
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
0 commit comments