diff --git a/dl/io/dl_file_xlsx.cpp b/dl/io/dl_file_xlsx.cpp index da455bb3..ca096121 100644 --- a/dl/io/dl_file_xlsx.cpp +++ b/dl/io/dl_file_xlsx.cpp @@ -15,7 +15,7 @@ bool Read(std::string_view path_name, std::string_view i_sheet_name, Vector2IsLevelLimit(level)) return;\ -LogLimit l{ level };\ +LogLevelSet l{ level };\ log_imp(str, DL_SOURCE_LOCATION_FORWARD); void log_notice0(std::string_view str, DL_SOURCE_LOCATION_IMP) @@ -357,7 +357,7 @@ void log_err0(const std::exception& e, DL_SOURCE_LOCATION_IMP) if (g_log->IsLevelLimit(LogSystem::Level::ERR)) return; - LogLimit l{ LogSystem::Level::ERR }; + LogLevelSet l{ LogSystem::Level::ERR }; #if DL_PLATFORM == DL_PLATFORM_WIN32 log_imp(fmt::format("捕获到C++异常:{}", CodeCvt::MultiByteToUtf8(e.what())), location); @@ -370,7 +370,7 @@ void log_err0(const std::system_error& e, DL_SOURCE_LOCATION_IMP) { if (g_log->IsLevelLimit(LogSystem::Level::ERR)) return; - LogLimit l{ LogSystem::Level::ERR }; + LogLevelSet l{ LogSystem::Level::ERR }; #if DL_PLATFORM == DL_PLATFORM_WIN32 log_imp(fmt::format("捕获到系统异常[{}]:{}", e.code().value(), CodeCvt::MultiByteToUtf8(e.what())), location); diff --git a/dl/io/dl_log.h b/dl/io/dl_log.h index dd9cf36a..0533613e 100644 --- a/dl/io/dl_log.h +++ b/dl/io/dl_log.h @@ -77,6 +77,7 @@ class LogSystem { friend class LogLimit; friend class LogStackTrack; + friend class LogLevelSet; public: //! 日志等级 越小越严重 enum class Level @@ -119,21 +120,7 @@ public: { return _logFile; } - /** - * @brief 设置日志输出等级 - * @param[in] level 限制等级 大于自己不输出 - * @note 必须调用PopLevelLimit出栈 - */ - void PushLevelLimit(Level level) - { - _mutexLevel.lock(); - _stackLevel.push(level); - } - void PopLevelLimit() - { - _stackLevel.pop(); - _mutexLevel.unlock(); - } + bool IsLevelLimit(Level level) { _mutexLevel.lock(); @@ -153,19 +140,6 @@ public: _levelMsgBox = level; } - - /** - * @brief 入栈设置 - * @param[in] setting 设置 - * @note 必须调用Pop出栈设置 - */ - void Push(const Setting& setting) - { - _mutexSetting.lock(); - _stackSetting.push(setting); - } - - std::mutex& GetMutex() { return _mutexOutput; } /** @@ -190,6 +164,22 @@ private: // 容易错误使用,改为私有(请使用LogLimit) /** * @brief 入栈设置 + * @param[in] setting 设置 + * @note 必须调用Pop出栈设置 + */ + void Push(const Setting& setting) + { + _mutexSetting.lock(); + _stackSetting.push(setting); + } + //! 出栈设置 + void Pop() + { + _stackSetting.pop(); + _mutexSetting.unlock(); + } + /** + * @brief 入栈设置 * @param[in] level 等级 * @note 【WARNING】必须调用Pop出栈设置 */ @@ -199,15 +189,36 @@ private: setting._level = level; Push(setting); } - - //! 出栈设置 - void Pop() + /** + * @brief 设置日志输出等级 + * @param[in] level 限制等级 大于自己不输出 + * @note 必须调用PopLevelLimit出栈 + */ + void PushLevelLimit(Level level) { - _stackSetting.pop(); - _mutexSetting.unlock(); + _mutexLevel.lock(); + _stackLevel.push(level); + } + void PopLevelLimit() + { + _stackLevel.pop(); + _mutexLevel.unlock(); } }; extern LogSystem* g_log; +//! 日志打印等级设置 +class LogLevelSet +{ +public: + LogLevelSet(LogSystem::Level level) + { + g_log->PushLevel(level); + } + ~LogLevelSet() + { + g_log->Pop(); + } +}; //! 日志打印限制 class LogLimit { diff --git a/dl/render/dl_factory.cpp b/dl/render/dl_factory.cpp index 13858e75..bf9ef641 100644 --- a/dl/render/dl_factory.cpp +++ b/dl/render/dl_factory.cpp @@ -669,7 +669,7 @@ dl::gcAnimation Factory::CreateAnimation(std::string_view name, std::string_view auto iter = _mapAnimationInfo.find(name); if (iter == _mapAnimationInfo.end()) { - log_err("创建精灵动画失败:{}:{}", name, state); + log_warn("创建精灵动画失败:{}:{}", name, state); return {}; } AnimationInfo& info = iter->second; @@ -677,7 +677,7 @@ dl::gcAnimation Factory::CreateAnimation(std::string_view name, std::string_view auto iter1 = info._allAni.find(state); if (iter1 == info._allAni.end()) { - log_err("创建精灵动画失败:{},没有:{}", name, state); + log_warn("创建精灵动画失败:{},没有:{}", name, state); return {}; } AnimationInfo::Node& node = iter1->second;