#include "Util.h" #include #include #include #include #include #include #include #include #include #ifdef Q_OS_WIN #include #endif static QMutex msgMutex; static std::shared_ptr logger; Util::Util() { } void Util::InitLogger(const QString& logPath, const QString& mark) { auto file_sink = std::make_shared(logPath.toStdString(), 1024 * 1024 * 50, 3); auto console_sink = std::make_shared(); file_sink->set_pattern("[%Y-%m-%d %H:%M:%S.%e][%l]: %v"); console_sink->set_pattern("%^[%Y-%m-%d %H:%M:%S.%e][%l]: %v%$"); std::vector sinks{file_sink, console_sink}; logger = std::make_shared(mark.toStdString(), sinks.begin(), sinks.end()); logger->set_level(spdlog::level::debug); spdlog::register_logger(logger); } void Util::ConsoleMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg) { Q_UNUSED(context); switch (type) { case QtDebugMsg: logger->debug(msg.toStdString()); break; case QtInfoMsg: logger->info(msg.toStdString()); break; case QtWarningMsg: logger->warn(msg.toStdString()); break; case QtCriticalMsg: logger->error(msg.toStdString()); break; case QtFatalMsg: logger->critical(msg.toStdString()); break; default: logger->warn("Unknown QtMsgType type."); break; } } QString DirFileHelper::GetErr() const { return QString(); } void DirFileHelper::registerPathCall(const std::function& call) { pathCall_ = call; } void DirFileHelper::registerFileCall(const std::function& call) { fileCall_ = call; }