68 lines
2.0 KiB
C++
68 lines
2.0 KiB
C++
#include "Socket/Log.hpp"
|
|
|
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
|
#include "spdlog/sinks/rotating_file_sink.h"
|
|
#ifdef _WIN32
|
|
#include "spdlog/sinks/msvc_sink.h"
|
|
#endif
|
|
|
|
#include "precomp.hpp"
|
|
|
|
namespace Chattr::log {
|
|
|
|
void setDefaultLogger(spdlog::level::level_enum logLevel, gsl::czstring logFileName, std::uint32_t logFileSize, std::uint32_t logFileCount) {
|
|
std::vector<spdlog::sink_ptr> sinks;
|
|
sinks.push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
|
|
sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(logFileName, logFileSize, logFileCount, false));
|
|
#ifdef _WIN32
|
|
sinks.push_back(std::make_shared<spdlog::sinks::msvc_sink_mt>());
|
|
#endif
|
|
auto chatteringLogger = std::make_shared<spdlog::logger>("Chattering Logger", begin(sinks), end(sinks));
|
|
chatteringLogger->set_level(logLevel);
|
|
spdlog::set_default_logger(chatteringLogger);
|
|
}
|
|
|
|
void critical(gsl::czstring msg) {
|
|
#ifdef _WIN32
|
|
LPSTR msgbuf = nullptr;
|
|
FormatMessageA(
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
NULL,
|
|
WSAGetLastError(),
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
(LPSTR)&msgbuf,
|
|
0,
|
|
NULL);
|
|
spdlog::critical("[{}] {}", msg, msgbuf);
|
|
LocalFree(msgbuf);
|
|
#elif __linux__
|
|
gsl::czstring msgbuf = strerror(errno);
|
|
spdlog::critical("[{}] {}", msg, msgbuf);
|
|
#else
|
|
#error "이 플랫폼은 지원되지 않습니다."
|
|
#endif
|
|
std::exit(EXIT_FAILURE);
|
|
}
|
|
|
|
void error(gsl::czstring msg) {
|
|
#ifdef _WIN32
|
|
LPSTR msgbuf = nullptr;
|
|
FormatMessageA(
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
NULL,
|
|
WSAGetLastError(),
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
(LPSTR)&msgbuf,
|
|
0,
|
|
NULL);
|
|
spdlog::error("[{}] {}", msg, msgbuf);
|
|
LocalFree(msgbuf);
|
|
#elif __linux__
|
|
gsl::czstring msgbuf = strerror(errno);
|
|
spdlog::error("[{}] {}", msg, msgbuf);
|
|
#else
|
|
#error "이 플랫폼은 지원되지 않습니다."
|
|
#endif
|
|
}
|
|
|
|
} |