8 Commits

5 changed files with 185 additions and 354 deletions

View File

@@ -15,12 +15,11 @@ jlog is a C++ library for logging to file, console, and event callbacks.
## Installation ## Installation
Include this repository as a CPM dependency, and link against the library. Include this repository as a CPM dependency, and link against the library.
(TODO: Show the relevant CMake script lines.)
```cmake ```cmake
CPMAddPackage( CPMAddPackage(
NAME jlog NAME jlog
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-2.zip URL https://git.redacted.cc/josh/jlog/archive/Prerelease-7.zip
) )
# ... # ...
include_directories(${jlog_SOURCE_DIR}/include) include_directories(${jlog_SOURCE_DIR}/include)
@@ -37,6 +36,8 @@ Using jlog is straightforward:
#include <jlog.h> #include <jlog.h>
int main() { int main() {
LOGLEVEL(jlog::severity::debug); // <- see jlog::severity for full list of log levels
INFO("This is barely useful information."); INFO("This is barely useful information.");
DEBUG("Debugging Information"); DEBUG("Debugging Information");
VERBOSE("Yadda Yadda Yadda"); VERBOSE("Yadda Yadda Yadda");
@@ -57,12 +58,10 @@ int main() {
* Custom Contexts: Allow users to specify custom logging contexts for better organization. * Custom Contexts: Allow users to specify custom logging contexts for better organization.
* Disable & sort by context (other categories?) * Disable & sort by context (other categories?)
* Custom Formats: Add support for custom log message formats.
* Documentation * Documentation
* Thread Safety * Thread Safety
* Memory Safety * Memory Safety
* Stream Support * Stream Support
* Identify File, Line, Function name via macros (I hate macros!!!)
## License ## License

View File

@@ -25,16 +25,18 @@
namespace jlog namespace jlog
{ {
enum class severity enum class severity : uint8_t
{ {
none, none,
verbose,
debug,
warning, warning,
error, error,
fatal fatal,
verbose,
debug,
}; };
inline severity loglevel = severity::debug; // Default log level always debug
struct LogEntry struct LogEntry
{ {
severity level; severity level;
@@ -63,75 +65,85 @@ namespace jlog
void log(std::vector<token> tokens); void log(std::vector<token> tokens);
void info(const std::string& message); // Generic formatters for building loggers.
void sinfo(const std::string& message); std::vector<token> trace_format(
void usinfo(const std::string& message); const std::string& func,
const std::string& file,
int line);
void verbose(const std::string& message); std::vector<token> log_format(
void sverbose(const std::string& message); const std::string& severity_name,
void usverbose(const std::string& message); const std::string& message,
const std::string& severity_colorCode = ansi_escape_codes::FG_WHITE);
void debug(const std::string& message); std::vector<token> log_detailed_format(
void sdebug(const std::string& message); const std::string& severity_name,
void usdebug(const std::string& message); const std::string& message,
const std::string& func,
const std::string& file,
int line,
const std::string& severity_colorCode = ansi_escape_codes::FG_WHITE);
void warning(const std::string& message); // Predefined generic loggers for jlog.
void swarning(const std::string& message); std::vector<token> info_format(const std::string& message);
void uswarning(const std::string& message);
void error(const std::string& message); std::vector<token> info_detailed_format(
void serror(const std::string& message); const std::string &message,
void userror(const std::string& message); const std::string &func,
const std::string &file,
int line);
void fatal(const std::string& message); std::vector<token> warning_format(const std::string& message);
void sfatal(const std::string& message);
void usfatal(const std::string& message);
void info_spec(const std::string& message, const std::string& func, const std::string& file, int line); std::vector<token> warning_detailed_format(
void sinfo_spec(const std::string& message, const std::string& func, const std::string& file, int line); const std::string &message,
void usinfo_spec(const std::string& message, const std::string& func, const std::string& file, int line); const std::string &func,
const std::string &file,
int line);
void verbose_spec(const std::string& message, const std::string& func, const std::string& file, int line); std::vector<token> error_format(const std::string& message);
void sverbose_spec(const std::string& message, const std::string& func, const std::string& file, int line);
void usverbose_spec(const std::string& message, const std::string& func, const std::string& file, int line);
void debug_spec(const std::string& message, const std::string& func, const std::string& file, int line); std::vector<token> error_detailed_format(
void sdebug_spec(const std::string& message, const std::string& func, const std::string& file, int line); const std::string &message,
void usdebug_spec(const std::string& message, const std::string& func, const std::string& file, int line); const std::string &func,
const std::string &file,
int line);
void warning_spec(const std::string& message, const std::string& func, const std::string& file, int line); std::vector<token> fatal_format(const std::string& message);
void swarning_spec(const std::string& message, const std::string& func, const std::string& file, int line);
void uswarning_spec(const std::string& message, const std::string& func, const std::string& file, int line);
void error_spec(const std::string& message, const std::string& func, const std::string& file, int line); std::vector<token> fatal_detailed_format(
void serror_spec(const std::string& message, const std::string& func, const std::string& file, int line); const std::string &message,
void userror_spec(const std::string& message, const std::string& func, const std::string& file, int line); const std::string &func,
const std::string &file,
int line);
void fatal_spec(const std::string& message, const std::string& func, const std::string& file, int line); std::vector<token> verbose_format(const std::string& message);
void sfatal_spec(const std::string& message, const std::string& func, const std::string& file, int line);
void usfatal_spec(const std::string& message, const std::string& func, const std::string& file, int line); std::vector<token> verbose_detailed_format(
const std::string &message,
const std::string &func,
const std::string &file,
int line);
std::vector<token> debug_format(const std::string& message);
std::vector<token> debug_detailed_format(
const std::string &message,
const std::string &func,
const std::string &file,
int line);
} }
#define INFO(i) jlog::info_spec(i, FUNCTION, __FILE__, __LINE__); #define INFO(i) if (jlog::loglevel >= jlog::severity::none) { jlog::log(jlog::info_detailed_format(i, FUNCTION, __FILE__, __LINE__)); };
#define SINFO(i) jlog::sinfo_spec(i, FUNCTION, __FILE__, __LINE__);
#define USINFO(i) jlog::usinfo_spec(i, FUNCTION, __FILE__, __LINE__);
#define VERBOSE(i) jlog::verbose_spec(i, FUNCTION, __FILE__, __LINE__); #define VERBOSE(i) if (jlog::loglevel >= jlog::severity::verbose) { jlog::log(jlog::verbose_detailed_format(i, FUNCTION, __FILE__, __LINE__)); };
#define SVERBOSE(i) jlog::sverbose_spec(i, FUNCTION, __FILE__, __LINE__);
#define USVERBOSE(i) jlog::usverbose_spec(i, FUNCTION, __FILE__, __LINE__);
#define DEBUG(i) jlog::debug_spec(i, FUNCTION, __FILE__, __LINE__); #define DEBUG(i) if (jlog::loglevel >= jlog::severity::debug) { jlog::log(jlog::debug_detailed_format(i, FUNCTION, __FILE__, __LINE__)); };
#define SDEBUG(i) jlog::sdebug_spec(i, FUNCTION, __FILE__, __LINE__);
#define USDEBUG(i) jlog::usdebug_spec(i, FUNCTION, __FILE__, __LINE__);
#define WARNING(i) jlog::warning_spec(i, FUNCTION, __FILE__, __LINE__); #define WARNING(i) if (jlog::loglevel >= jlog::severity::warning) { jlog::log(jlog::warning_detailed_format(i, FUNCTION, __FILE__, __LINE__)); };
#define SWARNING(i) jlog::swarning_spec(i, FUNCTION, __FILE__, __LINE__);
#define USWARNING(i) jlog::uswarning_spec(i, FUNCTION, __FILE__, __LINE__);
#define ERROR(i) jlog::error_spec(i, FUNCTION, __FILE__, __LINE__); #define ERROR(i) if (jlog::loglevel >= jlog::severity::error) { jlog::log(jlog::error_detailed_format(i, FUNCTION, __FILE__, __LINE__)); };
#define SERROR(i) jlog::serror_spec(i, FUNCTION, __FILE__, __LINE__);
#define USERROR(i) jlog::userror_spec(i, FUNCTION, __FILE__, __LINE__);
#define FATAL(i) jlog::fatal_spec(i, FUNCTION, __FILE__, __LINE__); #define FATAL(i) if (jlog::loglevel >= jlog::severity::fatal) { jlog::log(jlog::fatal_detailed_format(i, FUNCTION, __FILE__, __LINE__)); };
#define SFATAL(i) jlog::sfatal_spec(i, FUNCTION, __FILE__, __LINE__);
#define USFATAL(i) jlog::usfatal_spec(i, FUNCTION, __FILE__, __LINE__); #define LOGLEVEL(i) jlog::loglevel = i;

View File

@@ -1,7 +1,22 @@
#include <jlog/jlog.hpp> #include <jlog/jlog.hpp>
// Writing custom wrappers for jlog is super easy!
void coollog(std::vector<jlog::token> tokens) {
std::vector<jlog::token> wtokens;
auto group = jlog::token{.content = "COOLLOGGER"};
wtokens.push_back(group);
wtokens.insert(wtokens.end(), tokens.begin(), tokens.end());
jlog::log(wtokens);
}
// We can either define custom logging macros or redefine jlog's builtin macros.
#define COOLINFO(i) coollog(jlog::info_format(i));
#define COOLINFOTRACE(i) coollog(jlog::info_detailed_format(i, FUNCTION, __FILE__, __LINE__));
int main() int main()
{ {
LOGLEVEL(jlog::severity::debug); // <- see jlog::severity for full list of log levels
INFO("This is barely useful information."); INFO("This is barely useful information.");
DEBUG("Debugging Information"); DEBUG("Debugging Information");
VERBOSE("Yadda Yadda Yadda"); VERBOSE("Yadda Yadda Yadda");
@@ -9,22 +24,10 @@ int main()
ERROR("Oops, something went wrong."); ERROR("Oops, something went wrong.");
FATAL("Unrecoverable Error!!!"); FATAL("Unrecoverable Error!!!");
SINFO("This is even less useful information."); COOLINFO("This is really cool!!!");
SDEBUG("Shorter Debugging Information"); COOLINFOTRACE("THIS IS EVEN COOLER!!!");
SVERBOSE("Yadda Yadda");
SWARNING("Minute miscalculation!");
SERROR("Oops, something went wrong, but the programmer used the short error logger so you're fucked!");
SFATAL("Unrecoverable Error, but the programmer used the short fatal logger so you're even more fucked!!!");
USINFO("This is EVEN less useful information.");
USDEBUG("Ultra compact debugging information.");
USVERBOSE("Isn't this an oxymoron?");
USWARNING("Captain Qwark grade miscalculation!");
USERROR("You're fucked!");
USFATAL("You're super fucked!!!");
return 0; return 0;
///
} }
//Windows :( //Windows :(

View File

@@ -50,314 +50,129 @@ namespace jlog {
log_to_file("\n"); log_to_file("\n");
} }
void direct(const std::string &message) { log({{.content = message, .delimiter=""}});} // Generic formatters for building loggers.
std::vector<token> trace_format(
void info(const std::string &message) { const std::string& func,
auto timestamp = token{.content = get_timestamp()}; const std::string& file,
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"}; int line)
auto content = token{.content = message, .delimiter = ""}; {
//auto trace = token{.content = };
log({timestamp, severity, content});
}
void sinfo(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({severity, content});
}
void usinfo(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({severity, content});
}
void verbose(const std::string &message) {
auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_CYAN, .content = "VERBOSE"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({timestamp, severity, content});
//log(ansi_escape_codes::FG_CYAN, "VERBOSE", message);
}
void sverbose(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_CYAN, .content = "VERBOSE"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({severity, content});
//log(ansi_escape_codes::FG_CYAN, "VERBOSE", message);
}
void usverbose(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_CYAN, .content = "VERBOSE"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({severity, content});
//log(ansi_escape_codes::FG_CYAN, "VERBOSE", message);
}
void debug(const std::string &message) {
auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_GREEN, .content = "DEBUG"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({timestamp, severity, content});
}
void sdebug(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_GREEN, .content = "DEBUG"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({severity, content});
}
void usdebug(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_GREEN, .content = "DEBUG"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({severity, content});
}
void warning(const std::string &message) {
auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_YELLOW, .content = "WARNING"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({timestamp, severity, content});
//log(ansi_escape_codes::FG_YELLOW, "WARNING", message);
}
void uswarning(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_YELLOW, .content = "WARNING"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({severity, content});
//log(ansi_escape_codes::FG_YELLOW, "WARNING", message);
}
void error(const std::string &message) {
auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_RED, .content = "ERROR"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({timestamp, severity, content});
//log(ansi_escape_codes::FG_RED, "ERROR", message);
}
void userror(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_RED, .content = "ERROR"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = };
log({severity, content});
//log(ansi_escape_codes::FG_RED, "ERROR", message);
}
void fatal(const std::string &message) {
auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_BRIGHT_RED, .content = "FATAL"};
auto content = token{.content = message, .delimiter = ""};
log({timestamp, severity, content});
}
void usfatal(const std::string &message) {
//auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_BRIGHT_RED, .content = "FATAL"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
void info_spec(const std::string &message, const std::string &func, const std::string &file,
int line) {
auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"};
auto content = token{.content = message, .delimiter = ""};
auto trace = token{.content = func}; auto trace = token{.content = func};
auto filedata = token{.content = std::format("{}:{}", file, line)}; auto filedata = token{.content = std::format("{}:{}", file, line)};
log({timestamp, trace, filedata, severity, content}); return {trace, filedata};
} }
void sinfo_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> log_format(
int line) { const std::string& severity_name,
//auto timestamp = token{.content = get_timestamp()}; const std::string& message,
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"}; const std::string& severity_colorCode)
{
auto severity = token{.colorCode = severity_colorCode, .content = severity_name};
auto content = token{.content = message, .delimiter = ""}; auto content = token{.content = message, .delimiter = ""};
auto trace = token{.content = func}; return {severity, content};
auto filedata = token{.content = std::format("{}:{}", file, line)};
log({trace, filedata, severity, content});
//log({severity, content});
} }
void usinfo_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> log_detailed_format(
int line) { const std::string& severity_name,
//auto timestamp = token{.content = get_timestamp()}; const std::string& message,
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"}; const std::string& func,
auto content = token{.content = message, .delimiter = ""}; const std::string& file,
//auto trace = token{.content = func}; int line,
//auto filedata = token{.content = std::format("{}:{}", file, line)}; const std::string& severity_colorCode)
//log({trace, filedata, severity, content}); {
log({severity, content}); std::vector<token> tokens;
auto timestamp = token{.content = jlog::get_timestamp()};
auto tf_tokens = trace_format(func, file, line);
auto lf_tokens = log_format(severity_name, message, severity_colorCode);
tokens.push_back(timestamp);
tokens.insert(tokens.end(), tf_tokens.begin(), tf_tokens.end());
tokens.insert(tokens.end(), lf_tokens.begin(), lf_tokens.end());
return tokens;
} }
void verbose_spec(const std::string &message, const std::string &func, const std::string &file,
int line) {
auto timestamp = token{.content = get_timestamp()}; // Predefined generic loggers for jlog.
auto severity = token{.colorCode = ansi_escape_codes::FG_CYAN, .content = "VERBOSE"}; std::vector<token> info_format(const std::string& message)
auto content = token{.content = message, .delimiter = ""}; {
auto trace = token{.content = func}; return log_format("INFO", message);
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, std::vector<token> info_detailed_format(
int line) { const std::string &message,
//auto timestamp = token{.content = get_timestamp()}; const std::string &func,
auto severity = token{.colorCode = ansi_escape_codes::FG_CYAN, .content = "VERBOSE"}; const std::string &file,
auto content = token{.content = message, .delimiter = ""}; int line)
auto trace = token{.content = func}; {
auto filedata = token{.content = std::format("{}:{}", file, line)}; return log_detailed_format("INFO", message, func, file, line);
log({trace, filedata, severity, content});
} }
void usverbose_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> warning_format(const std::string& message)
int line) { {
//auto timestamp = token{.content = get_timestamp()}; return log_format("INFO", message, ansi_escape_codes::FG_YELLOW);
auto severity = token{.colorCode = ansi_escape_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({severity, content});
} }
void debug_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> warning_detailed_format(
int line) { const std::string &message,
auto timestamp = token{.content = get_timestamp()}; const std::string &func,
auto severity = token{.colorCode = ansi_escape_codes::FG_GREEN, .content = "DEBUG"}; const std::string &file,
auto content = token{.content = message, .delimiter = ""}; int line)
auto trace = token{.content = func}; {
auto filedata = token{.content = std::format("{}:{}", file, line)}; return log_detailed_format("WARNING", message, func, file, line, ansi_escape_codes::FG_YELLOW);
log({timestamp, trace, filedata, severity, content});
} }
void sdebug_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> error_format(const std::string& message)
int line) { {
//auto timestamp = token{.content = get_timestamp()}; return log_format("ERROR", message, ansi_escape_codes::FG_RED);
auto severity = token{.colorCode = ansi_escape_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, std::vector<token> error_detailed_format(
int line) { const std::string &message,
//auto timestamp = token{.content = get_timestamp()}; const std::string &func,
auto severity = token{.colorCode = ansi_escape_codes::FG_GREEN, .content = "DEBUG"}; const std::string &file,
auto content = token{.content = message, .delimiter = ""}; int line)
//auto trace = token{.content = func}; {
//auto filedata = token{.content = std::format("{}:{}", file, line)}; return log_detailed_format("ERROR", message, func, file, line, ansi_escape_codes::FG_RED);
log({severity, content});
} }
void warning_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> fatal_format(const std::string& message)
int line) { {
auto timestamp = token{.content = get_timestamp()}; return log_format("FATAL", message, ansi_escape_codes::FG_BRIGHT_RED);
auto severity = token{.colorCode = ansi_escape_codes::FG_YELLOW, .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, std::vector<token> fatal_detailed_format(
int line) { const std::string &message,
//auto timestamp = token{.content = get_timestamp()}; const std::string &func,
auto severity = token{.colorCode = ansi_escape_codes::FG_YELLOW, .content = "WARNING"}; const std::string &file,
auto content = token{.content = message, .delimiter = ""}; int line)
auto trace = token{.content = func}; {
auto filedata = token{.content = std::format("{}:{}", file, line)}; return log_detailed_format("FATAL", message, func, file, line, ansi_escape_codes::FG_BRIGHT_RED);
log({trace, filedata, severity, content});
} }
void uswarning_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> verbose_format(const std::string& message)
int line) { {
//auto timestamp = token{.content = get_timestamp()}; return log_format("VERBOSE", message, ansi_escape_codes::FG_CYAN);
auto severity = token{.colorCode = ansi_escape_codes::FG_YELLOW, .content = "WARNING"};
auto content = token{.content = message, .delimiter = ""};
//auto trace = token{.content = func};
//auto filedata = token{.content = std::format("{}:{}", file, line)};
log({severity, content});
} }
void error_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> verbose_detailed_format(
int line) { const std::string &message,
auto timestamp = token{.content = get_timestamp()}; const std::string &func,
auto severity = token{.colorCode = ansi_escape_codes::FG_RED, .content = "ERROR"}; const std::string &file,
auto content = token{.content = message, .delimiter = ""}; int line)
auto trace = token{.content = func}; {
auto filedata = token{.content = std::format("{}:{}", file, line)}; return log_detailed_format("VERBOSE", message, func, file, line, ansi_escape_codes::FG_CYAN);
log({timestamp, trace, filedata, severity, content});
} }
void serror_spec(const std::string &message, const std::string &func, const std::string &file, std::vector<token> debug_format(const std::string& message)
int line) { {
//auto timestamp = token{.content = get_timestamp()}; return log_format("DEBUG", message, ansi_escape_codes::FG_GREEN);
auto severity = token{.colorCode = ansi_escape_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, std::vector<token> debug_detailed_format(
int line) { const std::string &message,
//auto timestamp = token{.content = get_timestamp()}; const std::string &func,
auto severity = token{.colorCode = ansi_escape_codes::FG_RED, .content = "ERROR"}; const std::string &file,
auto content = token{.content = message, .delimiter = ""}; int line)
//auto trace = token{.content = func}; {
//auto filedata = token{.content = std::format("{}:{}", file, line)}; return log_detailed_format("DEBUG", message, func, file, line, ansi_escape_codes::FG_GREEN);
log({severity, content});
}
void fatal_spec(const std::string &message, const std::string &func, const std::string &file,
int line) {
auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_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({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 = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_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 timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_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({severity, content});
} }
} }

View File

@@ -55,6 +55,8 @@ namespace jlog {
log({{.content = message, .delimiter = ""}}); log({{.content = message, .delimiter = ""}});
} }
std::vector<token> info_format(const std::string& message
void info(const std::string& message) { void info(const std::string& message) {
auto timestamp = token{.content = get_timestamp()}; auto timestamp = token{.content = get_timestamp()};
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"}; auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"};