summary refs log tree commit diff
path: root/src/Logging.cpp
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-06-09 16:03:14 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-06-09 16:03:14 +0300
commitb89257a34b2a98b737f4ae544f7e436b9000b240 (patch)
tree81d7f355721541afbd91dc9a085abbb4666f3565 /src/Logging.cpp
parentInstall missing dependencies in travis-ci/appveyor (diff)
downloadnheko-b89257a34b2a98b737f4ae544f7e436b9000b240.tar.xz
Migrate to mtxclient for the http calls
Diffstat (limited to '')
-rw-r--r--src/Logging.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/Logging.cpp b/src/Logging.cpp
new file mode 100644

index 00000000..c6c1c502 --- /dev/null +++ b/src/Logging.cpp
@@ -0,0 +1,50 @@ +#include "Logging.hpp" + +#include <iostream> +#include <spdlog/sinks/file_sinks.h> + +namespace { +std::shared_ptr<spdlog::logger> db_logger = nullptr; +std::shared_ptr<spdlog::logger> net_logger = nullptr; +std::shared_ptr<spdlog::logger> main_logger = nullptr; + +constexpr auto MAX_FILE_SIZE = 1024 * 1024 * 6; +constexpr auto MAX_LOG_FILES = 3; +} + +namespace log { +void +init(const std::string &file_path) +{ + auto file_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>( + file_path, MAX_FILE_SIZE, MAX_LOG_FILES); + + auto console_sink = std::make_shared<spdlog::sinks::stdout_sink_mt>(); + + std::vector<spdlog::sink_ptr> sinks; + sinks.push_back(file_sink); + sinks.push_back(console_sink); + + net_logger = std::make_shared<spdlog::logger>("net", std::begin(sinks), std::end(sinks)); + main_logger = std::make_shared<spdlog::logger>("main", std::begin(sinks), std::end(sinks)); + db_logger = std::make_shared<spdlog::logger>("db", std::begin(sinks), std::end(sinks)); +} + +std::shared_ptr<spdlog::logger> +main() +{ + return main_logger; +} + +std::shared_ptr<spdlog::logger> +net() +{ + return net_logger; +} + +std::shared_ptr<spdlog::logger> +db() +{ + return db_logger; +} +}