From 4726e02afbbbccb3b7b5dabe22a3b0d6f21ff6d7 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sun, 11 Nov 2012 20:59:27 +0100 Subject: [PATCH] logging: add warning if no output module is selected If no daemon compatible logging module is selected, a message is displayed to avoid the user to look like mad for messages. --- src/suricata.c | 2 +- src/util-debug.c | 12 +++++++++++- src/util-debug.h | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/suricata.c b/src/suricata.c index b5e7e73866..ac89f13a06 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -1373,7 +1373,7 @@ int main(int argc, char **argv) /* Since our config is now loaded we can finish configurating the * logging module. */ - SCLogLoadConfig(); + SCLogLoadConfig(daemon); #ifdef __SC_CUDA_SUPPORT__ /* load the cuda configuration */ diff --git a/src/util-debug.c b/src/util-debug.c index 378d01184d..572690e800 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -1098,10 +1098,11 @@ void SCLogInitLogModule(SCLogInitData *sc_lid) return; } -void SCLogLoadConfig(void) +void SCLogLoadConfig(int daemon) { ConfNode *outputs; SCLogInitData *sc_lid; + int have_logging = 0; outputs = ConfGetNode("logging.outputs"); if (outputs == NULL) { @@ -1178,6 +1179,7 @@ void SCLogLoadConfig(void) "Logging to file requires a filename"); exit(EXIT_FAILURE); } + have_logging = 1; op_iface_ctx = SCLogInitFileOPIface(filename, format, level); } else if (strcmp(output->name, "syslog") == 0) { @@ -1195,6 +1197,7 @@ void SCLogLoadConfig(void) } printf("Initialization syslog logging with format \"%s\".\n", format); + have_logging = 1; op_iface_ctx = SCLogInitSyslogOPIface(facility, format, level); } else { @@ -1206,6 +1209,13 @@ void SCLogLoadConfig(void) } } + if (daemon && (have_logging == 0)) { + SCLogError(SC_ERR_MISSING_CONFIG_PARAM, + "NO logging compatible with daemon mode selected," + " suricata won't be able to log. Please update " + " 'logging.outputs' in the YAML."); + } + SCLogInitLogModule(sc_lid); SCLogDebug("sc_log_global_log_level: %d", sc_log_global_log_level); diff --git a/src/util-debug.h b/src/util-debug.h index 0d98d429c2..a778b98fd6 100644 --- a/src/util-debug.h +++ b/src/util-debug.h @@ -546,6 +546,6 @@ int SCLogDebugEnabled(void); void SCLogRegisterTests(void); -void SCLogLoadConfig(void); +void SCLogLoadConfig(int daemon); #endif /* __UTIL_DEBUG_H__ */