2018-07-17 16:37:25 +03:00
|
|
|
#include "Logging.h"
|
2018-06-09 16:03:14 +03:00
|
|
|
|
2018-08-08 14:15:14 +03:00
|
|
|
#include "spdlog/sinks/rotating_file_sink.h"
|
2018-09-04 13:17:21 +03:00
|
|
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
2018-06-09 16:03:14 +03:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace {
|
2018-06-10 20:03:45 +03:00
|
|
|
std::shared_ptr<spdlog::logger> db_logger = nullptr;
|
|
|
|
std::shared_ptr<spdlog::logger> net_logger = nullptr;
|
|
|
|
std::shared_ptr<spdlog::logger> crypto_logger = nullptr;
|
2018-06-14 02:28:35 +03:00
|
|
|
std::shared_ptr<spdlog::logger> ui_logger = nullptr;
|
2018-06-09 16:03:14 +03:00
|
|
|
|
|
|
|
constexpr auto MAX_FILE_SIZE = 1024 * 1024 * 6;
|
|
|
|
constexpr auto MAX_LOG_FILES = 3;
|
|
|
|
}
|
|
|
|
|
2018-06-14 02:28:35 +03:00
|
|
|
namespace nhlog {
|
2018-06-09 16:03:14 +03:00
|
|
|
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);
|
|
|
|
|
2018-09-04 13:17:21 +03:00
|
|
|
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
2018-06-09 16:03:14 +03:00
|
|
|
|
|
|
|
std::vector<spdlog::sink_ptr> sinks;
|
|
|
|
sinks.push_back(file_sink);
|
|
|
|
sinks.push_back(console_sink);
|
|
|
|
|
2018-06-14 02:28:35 +03:00
|
|
|
net_logger = std::make_shared<spdlog::logger>("net", std::begin(sinks), std::end(sinks));
|
|
|
|
ui_logger = std::make_shared<spdlog::logger>("ui", std::begin(sinks), std::end(sinks));
|
|
|
|
db_logger = std::make_shared<spdlog::logger>("db", std::begin(sinks), std::end(sinks));
|
2018-06-10 20:03:45 +03:00
|
|
|
crypto_logger =
|
|
|
|
std::make_shared<spdlog::logger>("crypto", std::begin(sinks), std::end(sinks));
|
2018-06-09 16:03:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<spdlog::logger>
|
2018-06-14 02:28:35 +03:00
|
|
|
ui()
|
2018-06-09 16:03:14 +03:00
|
|
|
{
|
2018-06-14 02:28:35 +03:00
|
|
|
return ui_logger;
|
2018-06-09 16:03:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<spdlog::logger>
|
|
|
|
net()
|
|
|
|
{
|
|
|
|
return net_logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<spdlog::logger>
|
|
|
|
db()
|
|
|
|
{
|
|
|
|
return db_logger;
|
|
|
|
}
|
2018-06-10 20:03:45 +03:00
|
|
|
|
|
|
|
std::shared_ptr<spdlog::logger>
|
|
|
|
crypto()
|
|
|
|
{
|
|
|
|
return crypto_logger;
|
|
|
|
}
|
2018-06-09 16:03:14 +03:00
|
|
|
}
|