jak-project/common/util/Assert.cpp
Tyler Wilding 4d751af38e
logs: replace every fmt::print with a lg call instead (#1368)
Favors the `lg` namespace over `fmt` directly, as this will output the
logs to a file / has log levels.

I also made assertion errors go to a file, this unfortunately means
importing `lg` and hence `fmt` which was attempted to be avoided before.
But I'm not sure how else to do this aspect without re-inventing the
file logging.

We have a lot of commented out prints as well that we should probably
cleanup at some point / switch them to trace level and default to `info`
level.

I noticed the pattern of disabling debug logs behind some boolean,
something to consider cleaning up in the future -- if our logs were more
structured (knowing where they are coming from) then a lot this
boilerplate could be eliminated.

Closes #1358
2022-10-01 11:58:36 -04:00

42 lines
1.2 KiB
C++

#include "Assert.h"
#ifndef NO_ASSERT
#include <cstdio>
#include <cstdlib>
#include <string_view>
#include "common/log/log.h"
void private_assert_failed(const char* expr,
const char* file,
int line,
const char* function,
const char* msg) {
if (!msg || msg[0] == '\0') {
std::string log = fmt::format("Assertion failed: '{}'\n\tSource: {}:{}\n\tFunction: {}\n", expr,
file, line, function);
lg::die(log);
} else {
std::string log =
fmt::format("Assertion failed: '{}'\n\tMessage: {}\n\tSource: {}:{}\n\tFunction: {}\n",
expr, msg, file, line, function);
lg::die(log);
}
abort();
}
void private_assert_failed(const char* expr,
const char* file,
int line,
const char* function,
const std::string_view& msg) {
if (msg.empty()) {
private_assert_failed(expr, file, line, function);
} else {
private_assert_failed(expr, file, line, function, msg.data());
}
}
#endif