日志打印修正

This commit is contained in:
2026-09-04 16:20:45 +08:00
parent 87d570c85b
commit 8a74e8ed00
4 changed files with 50 additions and 39 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ bool Read(std::string_view path_name, std::string_view i_sheet_name, Vector2<std
{
assert(ret.IsEmpty());
LogLimit l{ LogSystem::Level::ERR };
LogLevelSet l{ LogSystem::Level::ERR };
using namespace OpenXLSX;
XLDocument doc;
+3 -3
View File
@@ -308,7 +308,7 @@ void log_imp(std::string_view str, DL_SOURCE_LOCATION_IMP)
#define DL_LOG_OUTPUT(level)\
if (g_log->IsLevelLimit(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);
+44 -33
View File
@@ -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
{
+2 -2
View File
@@ -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;