Got logging and errors basically all working the way I want
This commit is contained in:
@@ -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"}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user