Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -56,6 +56,7 @@ namespace jlog
|
||||
|
||||
void set_default_logfile(const std::string& filename);
|
||||
|
||||
/// Returns a string timestamp in the format of 'YYYY-MM-DD hh:mm:ss.ms'
|
||||
std::string get_timestamp();
|
||||
|
||||
/// Writes an input string directly to standard output
|
||||
@@ -91,18 +92,33 @@ namespace jlog
|
||||
void log(std::vector<token> tokens);
|
||||
void ltlog(std::vector<token> tokens); // Just for debug purposes
|
||||
|
||||
// Generic formatters for building loggers.
|
||||
#pragma region Generic Formatters
|
||||
|
||||
/// Returns a pseudo-"stacktrace" formatted sequence of tokens.
|
||||
/// @param func The function name/signature to trace back to. Should be provided by a __FUNCTION__ macro variant.
|
||||
/// @param file The file name to trace back to. Should be provided by a __FILE__ macro variant.
|
||||
/// @param line The source-code line to trace back to. Should be provided by a __LINE__ macro variant.
|
||||
std::vector<token> trace_format(
|
||||
const std::string& func,
|
||||
const std::string& file,
|
||||
int line);
|
||||
|
||||
/// Returns a formatted sequence of tokens given a severity and message.
|
||||
/// @param severity_name The severity tag to prefix to the message. Could theoretically also be a context.
|
||||
/// @param message The actual message to include
|
||||
/// @param severity_cc The colorcode to assign to the severity. See color_codes.hpp
|
||||
std::vector<token> log_format(
|
||||
const std::string& severity_name,
|
||||
const std::string& message,
|
||||
const colorcode& severity_cc = color_codes::FG_WHITE);
|
||||
|
||||
/// Returns a more detailed formatted sequence of tokens.
|
||||
/// @param severity_name The severity tag to prefix to the message. Could theoretically also be a context.
|
||||
/// @param message The actual message to include
|
||||
/// @param func The function name/signature to trace back to. Should be provided by a __FUNCTION__ macro variant.
|
||||
/// @param file The file name to trace back to. Should be provided by a __FILE__ macro variant.
|
||||
/// @param line The source-code line to trace back to. Should be provided by a __LINE__ macro variant.
|
||||
/// @param severity_cc The colorcode to assign to the severity. See color_codes.hpp
|
||||
std::vector<token> log_detailed_format(
|
||||
const std::string& severity_name,
|
||||
const std::string& message,
|
||||
@@ -111,54 +127,96 @@ namespace jlog
|
||||
int line,
|
||||
const colorcode& severity_cc = color_codes::FG_WHITE);
|
||||
|
||||
// Predefined generic loggers for jlog.
|
||||
/// Returns a token sequence pre-formatted for the INFO log level.
|
||||
/// @param message The message to send out.
|
||||
std::vector<token> info_format(const std::string& message);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the INFO log level.
|
||||
/// @param message The message to send out.
|
||||
/// @param func The function name/signature to trace back to. Should be provided by a __FUNCTION__ macro variant.
|
||||
/// @param file The file name to trace back to. Should be provided by a __FILE__ macro variant.
|
||||
/// @param line The source-code line to trace back to. Should be provided by a __LINE__ macro variant.
|
||||
std::vector<token> info_detailed_format(
|
||||
const std::string &message,
|
||||
const std::string &func,
|
||||
const std::string &file,
|
||||
int line);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the WARNING log level.
|
||||
/// @param message The message to send out.
|
||||
std::vector<token> warning_format(const std::string& message);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the WARNING log level.
|
||||
/// @param message The message to send out.
|
||||
/// @param func The function name/signature to trace back to. Should be provided by a __FUNCTION__ macro variant.
|
||||
/// @param file The file name to trace back to. Should be provided by a __FILE__ macro variant.
|
||||
/// @param line The source-code line to trace back to. Should be provided by a __LINE__ macro variant.
|
||||
std::vector<token> warning_detailed_format(
|
||||
const std::string &message,
|
||||
const std::string &func,
|
||||
const std::string &file,
|
||||
int line);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the ERROR log level.
|
||||
/// @param message The message to send out.
|
||||
std::vector<token> error_format(const std::string& message);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the ERROR log level.
|
||||
/// @param message The message to send out.
|
||||
/// @param func The function name/signature to trace back to. Should be provided by a __FUNCTION__ macro variant.
|
||||
/// @param file The file name to trace back to. Should be provided by a __FILE__ macro variant.
|
||||
/// @param line The source-code line to trace back to. Should be provided by a __LINE__ macro variant.
|
||||
std::vector<token> error_detailed_format(
|
||||
const std::string &message,
|
||||
const std::string &func,
|
||||
const std::string &file,
|
||||
int line);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the FATAL log level.
|
||||
/// @param message The message to send out.
|
||||
std::vector<token> fatal_format(const std::string& message);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the FATAL log level.
|
||||
/// @param message The message to send out.
|
||||
/// @param func The function name/signature to trace back to. Should be provided by a __FUNCTION__ macro variant.
|
||||
/// @param file The file name to trace back to. Should be provided by a __FILE__ macro variant.
|
||||
/// @param line The source-code line to trace back to. Should be provided by a __LINE__ macro variant.
|
||||
std::vector<token> fatal_detailed_format(
|
||||
const std::string &message,
|
||||
const std::string &func,
|
||||
const std::string &file,
|
||||
int line);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the VERBOSE log level.
|
||||
/// @param message The message to send out.
|
||||
std::vector<token> verbose_format(const std::string& message);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the VERBOSE log level.
|
||||
/// @param message The message to send out.
|
||||
/// @param func The function name/signature to trace back to. Should be provided by a __FUNCTION__ macro variant.
|
||||
/// @param file The file name to trace back to. Should be provided by a __FILE__ macro variant.
|
||||
/// @param line The source-code line to trace back to. Should be provided by a __LINE__ macro variant.
|
||||
std::vector<token> verbose_detailed_format(
|
||||
const std::string &message,
|
||||
const std::string &func,
|
||||
const std::string &file,
|
||||
int line);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the DEBUG log level.
|
||||
/// @param message The message to send out.
|
||||
std::vector<token> debug_format(const std::string& message);
|
||||
|
||||
/// Returns a token sequence pre-formatted for the DEBUG log level.
|
||||
/// @param message The message to send out.
|
||||
/// @param func The function name/signature to trace back to. Should be provided by a __FUNCTION__ macro variant.
|
||||
/// @param file The file name to trace back to. Should be provided by a __FILE__ macro variant.
|
||||
/// @param line The source-code line to trace back to. Should be provided by a __LINE__ macro variant.
|
||||
std::vector<token> debug_detailed_format(
|
||||
const std::string &message,
|
||||
const std::string &func,
|
||||
const std::string &file,
|
||||
int line);
|
||||
#pragma endregion
|
||||
}
|
||||
|
||||
#define INFO(i) if (jlog::loglevel >= jlog::severity::none) { jlog::log(jlog::info_detailed_format(i, FUNCTION, __FILE__, __LINE__)); }
|
||||
|
@@ -131,145 +131,6 @@ namespace jlog
|
||||
return log_detailed_format("DEBUG", message, func, file, line, color_codes::FG_GREEN);
|
||||
}
|
||||
|
||||
void direct(const std::string& message)
|
||||
{
|
||||
log({{.content = message, .delimiter = ""}});
|
||||
}
|
||||
|
||||
void info(const std::string& message)
|
||||
{
|
||||
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({timestamp, severity, content});
|
||||
}
|
||||
|
||||
void sinfo(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void usinfo(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void verbose(const std::string& message)
|
||||
{
|
||||
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({timestamp, severity, content});
|
||||
}
|
||||
|
||||
void sverbose(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void usverbose(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void debug(const std::string& message)
|
||||
{
|
||||
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({timestamp, severity, content});
|
||||
}
|
||||
|
||||
void sdebug(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void usdebug(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void warning(const std::string& message)
|
||||
{
|
||||
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||
auto severity = token{.colorCode = color_codes::FG_YELLOW, .content = "WARNING"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({timestamp, severity, content});
|
||||
}
|
||||
|
||||
void swarning(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_YELLOW, .content = "WARNING"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void uswarning(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_YELLOW, .content = "WARNING"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void error(const std::string& message)
|
||||
{
|
||||
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||
auto severity = token{.colorCode = color_codes::FG_RED, .content = "ERROR"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({timestamp, severity, content});
|
||||
}
|
||||
|
||||
void serror(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_RED, .content = "ERROR"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void userror(const std::string& message)
|
||||
{
|
||||
auto severity = token{.colorCode = color_codes::FG_RED, .content = "ERROR"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void fatal(const std::string& message)
|
||||
{
|
||||
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||
auto severity = token{.colorCode = color_codes::FG_BRIGHT_RED, .content = "FATAL"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({timestamp, severity, content});
|
||||
}
|
||||
|
||||
void sfatal(const std::string& message)
|
||||
{
|
||||
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||
auto severity = token{.colorCode = color_codes::FG_BRIGHT_RED, .content = "FATAL"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
void usfatal(const std::string& message)
|
||||
{
|
||||
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||
auto severity = token{.colorCode = color_codes::FG_BRIGHT_RED, .content = "FATAL"};
|
||||
auto content = token{.content = message, .delimiter = ""};
|
||||
log({severity, content});
|
||||
}
|
||||
|
||||
std::vector<token> info_detailed_format(
|
||||
const std::string& message,
|
||||
const std::string& func,
|
||||
|
Reference in New Issue
Block a user