diff --git a/auditd-plugin-clickhouse.cpp b/auditd-plugin-clickhouse.cpp index c025600..1fb6333 100644 --- a/auditd-plugin-clickhouse.cpp +++ b/auditd-plugin-clickhouse.cpp @@ -794,6 +794,9 @@ int main(int argc, char **argv) } } + Logger::initialize(); + Logger::dump(); + read_datatypes_map(datatypes_filename); // If no limits are set, don't use special writer thread diff --git a/logging.cpp b/logging.cpp index 67e5433..6fc65fe 100644 --- a/logging.cpp +++ b/logging.cpp @@ -27,6 +27,7 @@ std::mutex Logger::s_mutex; Logger::Logger() + : m_initialized(false) { } @@ -47,6 +48,12 @@ void Logger::open(const char *filename) instance().open_impl(filename); } +void Logger::initialize() +{ + std::lock_guard lock(s_mutex); + instance().initialize_impl(); +} + void Logger::write(const char *format, ...) { std::lock_guard lock(s_mutex); @@ -67,6 +74,13 @@ void Logger::dump() void Logger::open_impl(const char *filename) { m_logfile_name = filename; + + initialize_impl(); +} + +void Logger::initialize_impl() +{ + m_initialized = true; } void Logger::write_impl(const char *format, va_list args) @@ -107,6 +121,11 @@ void Logger::write_impl(const char *format, va_list args) { m_lines.push_back(std::make_pair(datestring,data)); } + + if (m_initialized) + { + dump_impl(); + } } } diff --git a/logging.hpp b/logging.hpp index 296e896..ad55cec 100644 --- a/logging.hpp +++ b/logging.hpp @@ -34,6 +34,7 @@ public: static Logger& instance(); static void open(const char *filename); + static void initialize(); static void write(const char *format, ...); static void dump(); @@ -42,6 +43,7 @@ private: ~Logger(); void open_impl(const char *filename); + void initialize_impl(); void write_impl(const char *format, va_list args); void dump_impl(); @@ -52,6 +54,7 @@ private: std::list > m_lines; std::string m_logfile_name; + bool m_initialized; static std::mutex s_mutex; };