56 lines
1.1 KiB
C++
56 lines
1.1 KiB
C++
#include "dl_log.h"
|
|
|
|
#if (DL_PLATFORM == DL_PLATFORM_WIN32)
|
|
#define NOMINMAX
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
namespace dl
|
|
{
|
|
LogSystem* g_log = nullptr;
|
|
|
|
#if (DL_PLATFORM == DL_PLATFORM_WIN32)
|
|
void log(std::string_view str, const std::source_location location /*= std::source_location::current()*/)
|
|
{
|
|
const LogSystem::Setting& setting = g_log->GetSetting();
|
|
std::string s;
|
|
if (setting._bSourceLocation)
|
|
{
|
|
s += fmt::format("{}({}): ",
|
|
location.file_name(), location.line());
|
|
}
|
|
s += LogSystem::Level2String(setting._level);
|
|
s += ": ";
|
|
s += str;
|
|
if (setting._bStackTrace)
|
|
{
|
|
s += std::to_string(std::stacktrace::current());
|
|
}
|
|
std::cout << s << std::endl;
|
|
|
|
// 转为wstring再输出
|
|
DWORD len = MultiByteToWideChar(CP_UTF8, NULL, s.c_str(), -1, 0, 0);
|
|
std::wstring wcs;
|
|
wcs.resize(len);
|
|
MultiByteToWideChar(CP_UTF8, NULL, s.c_str(), -1, wcs.data(), len);
|
|
wcs.pop_back();
|
|
|
|
OutputDebugStringW(wcs.c_str());
|
|
OutputDebugStringW(L"\n");
|
|
}
|
|
#endif
|
|
|
|
|
|
#if (DL_PLATFORM == DL_PLATFORM_LINUX)
|
|
void log(std::string_view str)
|
|
{
|
|
std::cout << str << std::endl;
|
|
}
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|