Got logging and errors basically all working the way I want

This commit is contained in:
NaifBanana
2026-05-18 01:35:28 -05:00
parent 32ca555c49
commit 091867e77d
10 changed files with 465 additions and 291 deletions
+3 -4
View File
@@ -3,12 +3,11 @@
namespace nb {
const std::string Error<nb::NoneType>::type = "nb::Error";
const std::string Error<>::type = "nb::Error";
const ErrorCodeMap Error<nb::NoneType>::ErrorMessages = {
{Error::Codes::GENERAL, "General std::exception."},
{Error::Codes::UNDEFINED, "Undefined / general error."},
{Error::Codes::BADERRORCODE, "Unrecognized error code."}
{Error::Codes::STANDARD, "std::exception"},
{Error::Codes::UNDEFINED, "Error"}
};
}
+13 -3
View File
@@ -10,11 +10,21 @@ nb::DefaultDebugLogger logger(std::cout);
#endif // _NB_NO_LOGGER
bool nb::DefaultDebugLogger::process(const LogEvent& msg) {
constexpr size_t level_field_width = 3;
constexpr size_t msg_prompt_length = level_field_width+6;
for (const auto os : this->_ostream) {
*os << "[";
os->width(level_field_width);
(*os << std::to_string(msg.lvl)).width(level_field_width);
*os << "] :: ";
std::string fileloc="";
if (!msg.file.empty()) {
fileloc += "(" + msg.file + ":" + std::to_string(msg.line) + ") - ";
}
*os << indent_strblock(
msg.msg,
std::string(10, ' '),
"[ "+std::to_string(msg.lvl)+" ] : "
fileloc + msg.msg,
std::string(15 - msg_prompt_length, ' '),
""
) << nb::NEWLINE;
}
return true;
+28
View File
@@ -1 +1,29 @@
#include "StringUtils.hpp"
/* std::string nb::wstr_to_str(std::wstring in) {
std::size_t wstrlen = in.length();
char* c_str= new char[wstrlen];
std::wcstombs(c_str, in.c_str(), wstrlen);
std::string ret(c_str, wstrlen);
delete[] c_str;
return ret;
} */
std::string nb::indent_strblock(
std::string block,
std::string prepend,
std::string topIndent
) {
return topIndent + nb::find_and_replace(
block,
nb::NEWLINE,
nb::NEWLINE + prepend
);
}
std::string nb::indent_strblock(
std::string block,
std::string prepend
) {
return nb::indent_strblock(block, prepend, prepend);
}