#include "output-filestore.h"
typedef struct RootLogger_ {
+ OutputLogFunc LogFunc;
ThreadInitFunc ThreadInit;
ThreadDeinitFunc ThreadDeinit;
ThreadExitPrintStatsFunc ThreadExitPrintStats;
- OutputLogFunc LogFunc;
+ OutputGetActiveCountFunc ActiveCntFunc;
TAILQ_ENTRY(RootLogger_) entries;
} RootLogger;
-/* List of registered root loggers. */
+/* List of registered root loggers. These are registered at start up and
+ * are independent of configuration. Later we will build a list of active
+ * loggers based on configuration. */
static TAILQ_HEAD(, RootLogger_) registered_loggers =
TAILQ_HEAD_INITIALIZER(registered_loggers);
+/* List of active root loggers. This means that at least one logger is enabled
+ * for each root logger type in the config. */
+static TAILQ_HEAD(, RootLogger_) active_loggers =
+ TAILQ_HEAD_INITIALIZER(active_loggers);
+
typedef struct LoggerThreadStoreNode_ {
void *thread_data;
TAILQ_ENTRY(LoggerThreadStoreNode_) entries;
TmEcode OutputLoggerLog(ThreadVars *tv, Packet *p, void *thread_data)
{
LoggerThreadStore *thread_store = (LoggerThreadStore *)thread_data;
- RootLogger *logger = TAILQ_FIRST(®istered_loggers);
+ RootLogger *logger = TAILQ_FIRST(&active_loggers);
LoggerThreadStoreNode *thread_store_node = TAILQ_FIRST(thread_store);
while (logger && thread_store_node) {
if (logger->LogFunc != NULL) {
*data = (void *)thread_store;
RootLogger *logger;
- TAILQ_FOREACH(logger, ®istered_loggers, entries) {
+ TAILQ_FOREACH(logger, &active_loggers, entries) {
void *child_thread_data = NULL;
if (logger->ThreadInit != NULL) {
return TM_ECODE_FAILED;
LoggerThreadStore *thread_store = (LoggerThreadStore *)thread_data;
- RootLogger *logger = TAILQ_FIRST(®istered_loggers);
+ RootLogger *logger = TAILQ_FIRST(&active_loggers);
LoggerThreadStoreNode *thread_store_node = TAILQ_FIRST(thread_store);
while (logger && thread_store_node) {
if (logger->ThreadDeinit != NULL) {
void OutputLoggerExitPrintStats(ThreadVars *tv, void *thread_data)
{
LoggerThreadStore *thread_store = (LoggerThreadStore *)thread_data;
- RootLogger *logger = TAILQ_FIRST(®istered_loggers);
+ RootLogger *logger = TAILQ_FIRST(&active_loggers);
LoggerThreadStoreNode *thread_store_node = TAILQ_FIRST(thread_store);
while (logger && thread_store_node) {
if (logger->ThreadExitPrintStats != NULL) {
void OutputRegisterRootLogger(ThreadInitFunc ThreadInit,
ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats,
- OutputLogFunc LogFunc)
+ OutputLogFunc LogFunc, OutputGetActiveCountFunc ActiveCntFunc)
{
RootLogger *logger = SCCalloc(1, sizeof(*logger));
if (logger == NULL) {
logger->ThreadDeinit = ThreadDeinit;
logger->ThreadExitPrintStats = ThreadExitPrintStats;
logger->LogFunc = LogFunc;
+ logger->ActiveCntFunc = ActiveCntFunc;
TAILQ_INSERT_TAIL(®istered_loggers, logger, entries);
}
+static void OutputRegisterActiveLogger(RootLogger *reg)
+{
+ RootLogger *logger = SCCalloc(1, sizeof(*logger));
+ if (logger == NULL) {
+ FatalError(SC_ERR_MEM_ALLOC, "failed to alloc root logger");
+ }
+ logger->ThreadInit = reg->ThreadInit;
+ logger->ThreadDeinit = reg->ThreadDeinit;
+ logger->ThreadExitPrintStats = reg->ThreadExitPrintStats;
+ logger->LogFunc = reg->LogFunc;
+ logger->ActiveCntFunc = reg->ActiveCntFunc;
+ TAILQ_INSERT_TAIL(&active_loggers, logger, entries);
+}
+
+void OutputSetupActiveLoggers(void)
+{
+ RootLogger *logger = TAILQ_FIRST(®istered_loggers);
+ while (logger) {
+ uint32_t cnt = logger->ActiveCntFunc();
+ if (cnt) {
+ OutputRegisterActiveLogger(logger);
+ }
+
+ logger = TAILQ_NEXT(logger, entries);
+ }
+}
+
+void OutputClearActiveLoggers(void)
+{
+ RootLogger *logger;
+ while ((logger = TAILQ_FIRST(&active_loggers)) != NULL) {
+ TAILQ_REMOVE(&active_loggers, logger, entries);
+ SCFree(logger);
+ }
+}
+
void TmModuleLoggerRegister(void)
{
OutputRegisterRootLoggers();
typedef OutputInitResult (*OutputInitFunc)(ConfNode *);
typedef OutputInitResult (*OutputInitSubFunc)(ConfNode *, OutputCtx *);
typedef TmEcode (*OutputLogFunc)(ThreadVars *, Packet *, void *);
+typedef uint32_t (*OutputGetActiveCountFunc)(void);
typedef struct OutputModule_ {
LoggerId logger_id;
void OutputRegisterRootLogger(ThreadInitFunc ThreadInit,
ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats,
- OutputLogFunc LogFunc);
+ OutputLogFunc LogFunc, OutputGetActiveCountFunc ActiveCntFunc);
void TmModuleLoggerRegister(void);
TmEcode OutputLoggerLog(ThreadVars *, Packet *, void *);
TmEcode OutputLoggerThreadDeinit(ThreadVars *, void *);
void OutputLoggerExitPrintStats(ThreadVars *, void *);
+void OutputSetupActiveLoggers(void);
+void OutputClearActiveLoggers(void);
+
#endif /* ! __OUTPUT_H__ */