auditd-plugin-clickhouse/logging.hpp

63 lines
1.6 KiB
C++

/*
* This is an auditd plugin for sending auditd data
* to clickhouse DB.
* Copyright (C) 2020 Aleksei Nikiforov <darktemplar@basealt.ru>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef AUDITD_PLUGIN_CLICKHOUSE_LOGGING_HPP
#define AUDITD_PLUGIN_CLICKHOUSE_LOGGING_HPP
#include <string>
#include <list>
#include <mutex>
#include <utility>
#include <stdio.h>
#include <stdarg.h>
class Logger
{
public:
static Logger& instance();
static void open(const char *filename);
static void initialize();
static void write(const char *format, ...);
static void dump();
private:
Logger();
~Logger();
void open_impl(const char *filename);
void initialize_impl();
void write_impl(const char *format, va_list args);
void dump_impl();
std::string getdatestring() const;
Logger(const Logger &other) = delete;
Logger& operator=(const Logger &other) = delete;
std::list<std::pair<std::string, std::string> > m_lines;
std::string m_logfile_name;
bool m_initialized;
static std::mutex s_mutex;
};
#endif /* AUDITD_PLUGIN_CLICKHOUSE_LOGGING_HPP */