Core/Error: Make error log only the filename where the error occurred

This commit is contained in:
SirLynix 2023-12-04 18:22:40 +01:00
parent 5253a80a24
commit 62d5e611f1
2 changed files with 5 additions and 5 deletions

View File

@ -38,7 +38,7 @@ namespace Nz
static ErrorModeFlags ApplyFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags); static ErrorModeFlags ApplyFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags);
static constexpr std::string_view GetCurrentFileRelativeToEngine(std::string_view file); static constexpr std::string_view TranslateFilepath(std::string_view file);
static ErrorModeFlags GetFlags(); static ErrorModeFlags GetFlags();
static std::string GetLastError(std::string_view* file = nullptr, unsigned int* line = nullptr, std::string_view* function = nullptr); static std::string GetLastError(std::string_view* file = nullptr, unsigned int* line = nullptr, std::string_view* function = nullptr);
static unsigned int GetLastSystemErrorCode(); static unsigned int GetLastSystemErrorCode();

View File

@ -4,12 +4,12 @@
namespace Nz namespace Nz
{ {
constexpr std::string_view Error::GetCurrentFileRelativeToEngine(std::string_view file) constexpr std::string_view Error::TranslateFilepath(std::string_view file)
{ {
if (std::size_t offset = file.find("NazaraEngine/"); offset != file.npos) if (std::size_t offset = file.rfind('/'); offset != file.npos)
return file.substr(offset); return file.substr(offset);
if (std::size_t offset = file.find("NazaraEngine\\"); offset != file.npos) if (std::size_t offset = file.rfind('\\'); offset != file.npos)
return file.substr(offset); return file.substr(offset);
return file; return file;
@ -22,6 +22,6 @@ namespace Nz
inline void Error::Trigger(ErrorType type, unsigned int line, std::string_view file, std::string_view function, std::string error) inline void Error::Trigger(ErrorType type, unsigned int line, std::string_view file, std::string_view function, std::string error)
{ {
return TriggerInternal(type, std::move(error), line, GetCurrentFileRelativeToEngine(file), function); return TriggerInternal(type, std::move(error), line, TranslateFilepath(file), function);
} }
} }