22#if DL_PLATFORM == DL_PLATFORM_WIN32
24#include <source_location>
25#define DL_SOURCE_LOCATION std::source_location location = std::source_location::current()
26#define DL_SOURCE_LOCATION_IMP std::source_location location
27#define DL_SOURCE_LOCATION_CALL std::source_location::current()
28#define DL_SOURCE_LOCATION_FORWARD location
30#define DL_SOURCE_LOCATION const char* file = __FILE__, int line = __LINE__
31#define DL_SOURCE_LOCATION_IMP const char* file, int line
32#define DL_SOURCE_LOCATION_CALL __FILE__, __LINE__
33#define DL_SOURCE_LOCATION_FORWARD file, line
47#if DL_PLATFORM == DL_PLATFORM_WIN32
48#define DL_MAKE_SOURCE_LOCATION(loc) \
49 LogSourceLocation loc;\
50 loc._file = location.file_name();\
51 loc._func = location.function_name();\
52 loc._line = location.line();\
53 loc._column = location.column();
55#define DL_MAKE_SOURCE_LOCATION(loc) \
56 LogSourceLocation loc;\
58 loc._func = __func__;\
63#include <fmt/format.h>
68 "damage",
"err",
"warn",
"notice",
"msg",
"info",
"test",
"pause",
106 _mutexSetting.lock();
107 Setting& ret = _stackSetting.top();
108 _mutexSetting.unlock();
118 void SetLogFile(std::string_view path, std::string_view name = {},
bool clear =
true);
127 bool ret = level > _stackLevel.top();
128 _mutexLevel.unlock();
135 return level <= _levelMsgBox;
140 _levelMsgBox = level;
150 size_t index = (size_t)level;
156 std::stack<Setting> _stackSetting;
157 std::stack<Level> _stackLevel;
159 static std::string _logFile;
160 std::recursive_mutex _mutexSetting;
161 std::recursive_mutex _mutexLevel;
162 std::mutex _mutexOutput;
170 void Push(
const Setting& setting)
172 _mutexSetting.lock();
173 _stackSetting.push(setting);
179 _mutexSetting.unlock();
186 void PushLevel(
Level level)
189 setting._level = level;
197 void PushLevelLimit(
Level level)
200 _stackLevel.push(level);
205 _mutexLevel.unlock();
215 g_log->PushLevel(level);
229 g_log->PushLevelLimit(level);
233 g_log->PopLevelLimit();
257 printf(
"%s", str.data());
277#define log_(...) log(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
278#define log_pause(...) log_pause0(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
279#define log_test(...) log_test0(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
280#define log_info(...) log_info0(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
281#define log_msg(...) log_msg0(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
282#define log_notice(...) log_notice0(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
283#define log_warn(...) log_warn0(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
284#define log_err(...) log_err0(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
285#define log_damage(...) log_damage0(fmt::format(__VA_ARGS__), DL_SOURCE_LOCATION_CALL)
LogLevelSet(LogSystem::Level level)
LogLimit(LogSystem::Level level=LogSystem::Level::DAMAGE)
默认为最高等级,用于屏蔽消息输出
LogStackTrack(bool open=true)
bool IsLevelLimit(Level level)
const Setting & GetSetting()
返回当前设置
void SetLogFile(std::string_view path, std::string_view name={}, bool clear=true)
设置日志文件路径(非线程安全)
static std::string_view Level2String(Level level)
日志等级转字符串
bool IsLevelMsgBox(Level level)
检查等级是否可以弹窗(小于等于自己)
friend class LogStackTrack
void SetLevelMsgBox(Level level)
设置弹窗等级(小于等于自己才弹,越小越严重)
#define DL_SOURCE_LOCATION
constexpr std::array< std::string_view, 9 > DL_LOG_SYSTEM_LEVLE_NAME
void log_msg0(std::string_view str, DL_SOURCE_LOCATION)
void log_easy(std::string_view str)
输出日志
void Output(std::string_view str)
打印到标准输出、vs、日志文件
void log(std::string_view str, DL_SOURCE_LOCATION)
以当前设置输出
void log_err0(std::string_view str, DL_SOURCE_LOCATION)
void log_info0(std::string_view str, DL_SOURCE_LOCATION)
void log_test0(std::string_view str, DL_SOURCE_LOCATION)
void log_pause0(std::string_view str, DL_SOURCE_LOCATION)
void log_warn0(std::string_view str, DL_SOURCE_LOCATION)
void log_notice0(std::string_view str, DL_SOURCE_LOCATION)
void log_damage0(std::string_view str, DL_SOURCE_LOCATION)