[ox/std] Cleanup logging output
This commit is contained in:
parent
2a58490521
commit
5834b9c98d
15
deps/ox/src/ox/std/assert.hpp
vendored
15
deps/ox/src/ox/std/assert.hpp
vendored
@ -36,8 +36,8 @@ constexpr void assertFunc(CRStringView file, int line, bool pass, [[maybe_unused
|
||||
if (!pass) {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
#ifdef OX_USE_STDLIB
|
||||
oxErrf("\n\033[31;1;1mASSERT FAILURE:\033[0m [{}:{}]: {}\n", file, line, msg);
|
||||
printStackTrace(2);
|
||||
auto output = sfmt("\n\033[31;1;1mASSERT FAILURE:\033[0m [{}:{}]: {}\n", file, line, msg);
|
||||
output += genStackTrace(2);
|
||||
oxTracef("assert", "Failed assert: {} ({}) [{}:{}]", msg, assertTxt, file, line);
|
||||
std::abort();
|
||||
#else
|
||||
@ -55,15 +55,16 @@ constexpr void assertFunc(CRStringView file, int line, const Error &err, CRStrin
|
||||
if (err) {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
#if defined(OX_USE_STDLIB)
|
||||
oxErrf("\n\033[31;1;1mASSERT FAILURE:\033[0m [{}:{}]: {}\n", file, line, assertMsg);
|
||||
auto msg = sfmt("\n\033[31;1;1mASSERT FAILURE:\033[0m [{}:{}]: {}\n", file, line, assertMsg);
|
||||
if (err.msg) {
|
||||
oxErrf("\tError Message:\t{}\n", err.msg);
|
||||
msg += sfmt("\tError Message:\t{}\n", err.msg);
|
||||
}
|
||||
oxErrf("\tError Code:\t{}\n", static_cast<ErrorCode>(err));
|
||||
msg += sfmt("\tError Code:\t{}\n", static_cast<ErrorCode>(err));
|
||||
if (err.file != nullptr) {
|
||||
oxErrf("\tError Location:\t{}:{}\n", err.file, err.line);
|
||||
msg += sfmt("\tError Location:\t{}:{}\n", err.file, err.line);
|
||||
}
|
||||
printStackTrace(2);
|
||||
msg += genStackTrace(2);
|
||||
oxErr(msg);
|
||||
oxTracef("assert", "Failed assert: {} [{}:{}]", assertMsg, file, line);
|
||||
std::abort();
|
||||
#else
|
||||
|
22
deps/ox/src/ox/std/stacktrace.cpp
vendored
22
deps/ox/src/ox/std/stacktrace.cpp
vendored
@ -57,6 +57,28 @@ static auto symbolicate([[maybe_unused]]void **frames,
|
||||
}
|
||||
#endif // defined(OX_USE_STDLIB) && __has_include(<unistd.h>)
|
||||
|
||||
ox::String genStackTrace([[maybe_unused]]unsigned shave) noexcept {
|
||||
ox::String out;
|
||||
#if defined(OX_USE_STDLIB) && __has_include(<unistd.h>) && __has_include(<execinfo.h>)
|
||||
constexpr auto FrameCnt = 100;
|
||||
Vector<void*, FrameCnt> frames(FrameCnt);
|
||||
#ifdef OX_OS_FreeBSD
|
||||
using FrameCnt_t = unsigned;
|
||||
#else
|
||||
using FrameCnt_t = signed;
|
||||
#endif
|
||||
frames.resize(static_cast<std::size_t>(backtrace(frames.data(), static_cast<FrameCnt_t>(frames.size()))));
|
||||
if (frames.size() - shave > 2) {
|
||||
const auto symbolicatedStacktrace = symbolicate(frames.data() + shave, frames.size() - shave, "\t");
|
||||
out+= "Stacktrace:\n";
|
||||
for (const auto &s : symbolicatedStacktrace) {
|
||||
out += sfmt("\t{}\n", s);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return out;
|
||||
}
|
||||
|
||||
void printStackTrace([[maybe_unused]]unsigned shave) noexcept {
|
||||
#if defined(OX_USE_STDLIB) && __has_include(<unistd.h>) && __has_include(<execinfo.h>)
|
||||
constexpr auto FrameCnt = 100;
|
||||
|
5
deps/ox/src/ox/std/stacktrace.hpp
vendored
5
deps/ox/src/ox/std/stacktrace.hpp
vendored
@ -8,8 +8,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "string.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
[[nodiscard]]
|
||||
ox::String genStackTrace([[maybe_unused]]unsigned shave) noexcept;
|
||||
|
||||
/**
|
||||
* Prints a stack trace to stderr.
|
||||
*
|
||||
|
6
deps/ox/src/ox/std/tracehook.cpp
vendored
6
deps/ox/src/ox/std/tracehook.cpp
vendored
@ -66,8 +66,12 @@ void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line,
|
||||
[[maybe_unused]] const char *ch, [[maybe_unused]] const char *msg) {
|
||||
#if defined(OX_USE_STDLIB)
|
||||
if (OxPrintTrace) {
|
||||
auto m = std::string_view{msg};
|
||||
if (m.ends_with('\n')) {
|
||||
m = std::string_view{msg, m.size() - 1};
|
||||
}
|
||||
std::cout << std::setw(53) << std::left << ch << "| ";
|
||||
std::cout << std::setw(65) << std::left << msg << '|';
|
||||
std::cout << std::setw(65) << std::left << m << '|';
|
||||
std::cout << " " << file << ':' << line << "\n";
|
||||
} else if (ox::strcmp(ch, "debug") == 0 || ox::strcmp(ch, "info") == 0) {
|
||||
printf("%s\n", msg);
|
||||
|
Loading…
Reference in New Issue
Block a user