|
|
|
@@ -33,6 +33,18 @@ namespace jlog
|
|
|
|
|
|
|
|
|
|
void log_to_console(const std::string& message)
|
|
|
|
|
{
|
|
|
|
|
// Beat windows into submission and make it use ANSI color codes
|
|
|
|
|
// This also looks fugly, but it works
|
|
|
|
|
#ifdef __WIN32
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
DWORD consoleMode;
|
|
|
|
|
GetConsoleMode( handleOut , &consoleMode);
|
|
|
|
|
consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
|
|
|
|
consoleMode |= DISABLE_NEWLINE_AUTO_RETURN;
|
|
|
|
|
SetConsoleMode( handleOut , consoleMode );
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
std::cout << message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -55,25 +67,53 @@ namespace jlog
|
|
|
|
|
stream << message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//std::string toks2msg(std::vector<token> tokens, std::function<std::string(token)> formatter)
|
|
|
|
|
//{
|
|
|
|
|
// std::string msg;
|
|
|
|
|
// for (const token& t: tokens)
|
|
|
|
|
// {
|
|
|
|
|
// msg += formatter(t);
|
|
|
|
|
// }
|
|
|
|
|
// return msg;
|
|
|
|
|
//}
|
|
|
|
|
std::string toks2msg(std::vector<token> tokens, std::function<std::string(token)> formatter)
|
|
|
|
|
{
|
|
|
|
|
std::string msg;
|
|
|
|
|
for (const token& t: tokens)
|
|
|
|
|
{
|
|
|
|
|
msg += formatter(t);
|
|
|
|
|
}
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//std::string toks2consoleMsg(std::vector<token> tokens)
|
|
|
|
|
//{
|
|
|
|
|
// return toks2msg(tokens, consoleMsgFormatter);
|
|
|
|
|
//}
|
|
|
|
|
std::string toks2consoleMsg(std::vector<token> tokens)
|
|
|
|
|
{
|
|
|
|
|
return toks2msg(tokens, consoleMsgFormatter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//std::string toks2logfileMsg(std::vector<token> tokens)
|
|
|
|
|
//{
|
|
|
|
|
// return toks2msg(tokens, logfileMsgFormatter);
|
|
|
|
|
//}
|
|
|
|
|
std::string toks2logfileMsg(std::vector<token> tokens)
|
|
|
|
|
{
|
|
|
|
|
return toks2msg(tokens, logfileMsgFormatter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string consoleMsgFormatter(token t)
|
|
|
|
|
{
|
|
|
|
|
if (!t.delimiter.empty())
|
|
|
|
|
{
|
|
|
|
|
return std::format("{}{}{}{}{} ", t.colorCode.ansi_code, t.delimiter[0], t.content, t.delimiter[1], ansi_escape_codes::RESET);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::format("{}{}{} ", t.colorCode.ansi_code, t.content, ansi_escape_codes::RESET);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string logfileMsgFormatter(token t)
|
|
|
|
|
{
|
|
|
|
|
if (!t.delimiter.empty())
|
|
|
|
|
{
|
|
|
|
|
return std::format("{}{}{} ", t.delimiter[0], t.content, t.delimiter[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return t.content + " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log(const std::vector<token>& tokens, const std::string& filename)
|
|
|
|
|
{
|
|
|
|
|
log_to_console(toks2consoleMsg(tokens));
|
|
|
|
|
log_to_console("\n");
|
|
|
|
|
log_to_file(filename, toks2logfileMsg(tokens));
|
|
|
|
|
log_to_file(filename, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log(const std::vector<token>& tokens)
|
|
|
|
|
{
|
|
|
|
@@ -84,7 +124,7 @@ namespace jlog
|
|
|
|
|
void ltlog(const std::vector<token>& tokens)
|
|
|
|
|
{
|
|
|
|
|
log(tokens);
|
|
|
|
|
//log_to_file("logtest.log", toks2logfileMsg(tokens) + "\n");
|
|
|
|
|
log_to_file("logtest.log", toks2logfileMsg(tokens) + "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<token> trace_format(
|
|
|
|
@@ -208,161 +248,4 @@ namespace jlog
|
|
|
|
|
tokens.insert(tokens.end(), lf_tokens.begin(), lf_tokens.end());
|
|
|
|
|
return tokens;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void info_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({timestamp, trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sinfo_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void usinfo_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
log({severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void verbose_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({timestamp, trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sverbose_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void usverbose_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
log({severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void debug_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({timestamp, trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sdebug_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void usdebug_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
log({severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void warning_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "WARNING"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({timestamp, trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void swarning_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "WARNING"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uswarning_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "WARNING"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
log({severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void error_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "ERROR"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({timestamp, trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void serror_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_RED, .content = "ERROR"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void userror_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_RED, .content = "ERROR"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
log({severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fatal_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_RED, .content = "FATAL"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({timestamp, trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sfatal_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_BRIGHT_RED, .content = "FATAL"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
auto trace = token{.content = func};
|
|
|
|
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
|
|
|
|
log({trace, filedata, severity, content});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void usfatal_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
|
|
|
|
{
|
|
|
|
|
auto severity = token{.colorCode = color_codes::FG_BRIGHT_RED, .content = "FATAL"};
|
|
|
|
|
auto content = token{.content = message, .delimiter = ""};
|
|
|
|
|
log({severity, content});
|
|
|
|
|
}
|
|
|
|
|
}
|