15 Commits

Author SHA1 Message Date
Redacted
80d9bcd240 Update include/jlog/jlog.hpp
Fix definition clash when using in multiple projects.
2024-06-18 14:40:31 -04:00
2799c918b8 Implemented log level handling/switching. Use LOGLEVEL macro for setting level/severity. See jlog::severity in jlog.hpp for more information. 2024-06-18 12:11:41 -04:00
a86e70a055 Merge remote-tracking branch 'origin/main' 2024-06-18 11:10:20 -04:00
3cf70f5f4f removed todo from README 2024-06-18 11:10:13 -04:00
3a28d4e43b Update ansi_escape_codes.hpp
Fix problem that'd sometimes cause errors when using the macros in a lot of different files.
2024-06-18 00:44:07 -04:00
e5cfd25fcc Merge remote-tracking branch 'origin/main' 2024-06-17 13:51:29 -04:00
b0793828f6 Try to make dependency private 2024-06-17 13:51:18 -04:00
4b512df77a Windows color codes. 2024-06-16 18:52:05 -04:00
eb21b8a81f Windows 2024-06-16 11:07:24 -07:00
maxbyte9p
f22b869335 Added short and ultra short logger messages. 2024-06-15 21:09:28 -04:00
8df5a62597 Fixing more typos in README.md 2024-06-14 13:01:32 -04:00
cd756f7e61 Attempt to publicly expose Event subdependency 2024-06-14 12:54:13 -04:00
24de473770 Add sample output image 2024-06-14 12:48:25 -04:00
17bd6b17ff Fix up README 2024-06-14 12:47:46 -04:00
7ab579fa0b Implement macros that capture current file, line, and function name. 2024-06-13 13:48:20 -04:00
10 changed files with 933 additions and 205 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/cmake-build-debug
/.idea

View File

@@ -16,8 +16,14 @@ include(cmake/CPM.cmake)
file(GLOB_RECURSE jlog_HEADERS "include/jlog/*.h" "include/jlog/*.hpp") file(GLOB_RECURSE jlog_HEADERS "include/jlog/*.h" "include/jlog/*.hpp")
file(GLOB_RECURSE jlog_SRC "src/jlog/*.c" "src/jlog/*.cpp")
if(UNIX AND NOT APPLE)
file(GLOB_RECURSE jlog_SRC "src/jlog/linux/*.c" "src/jlog/linux/*.cpp")
endif()
if(WIN32)
file(GLOB_RECURSE jlog_SRC "src/jlog/windows/*.c" "src/jlog/windows/*.cpp")
endif()
include_directories("include") include_directories("include")
CPMAddPackage( CPMAddPackage(
@@ -42,5 +48,7 @@ install(FILES ${jlog_HEADERS} DESTINATION include/${PROJECT_NAME})
#add_subdirectory(tests) #add_subdirectory(tests)
target_link_libraries(jlog PRIVATE Event)
add_executable(LoggerDemo main.cpp) add_executable(LoggerDemo main.cpp)
target_link_libraries(LoggerDemo ${PROJECT_NAME} Event) target_link_libraries(LoggerDemo PUBLIC ${PROJECT_NAME})

View File

@@ -15,17 +15,16 @@ 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 Event NAME jlog
URL https://git.redacted.cc/josh/Event/archive/Release-6.zip URL https://git.redacted.cc/josh/jlog/archive/Prerelease-2.zip
) )
# ... # ...
include_directories(${jlog_SOURCE_DIR}/include) include_directories(${jlog_SOURCE_DIR}/include)
# ... # ...
target_link_libraries(YourProgram ${PROJECT_NAME} jlog) target_link_libraries(YourProgram ... jlog)
``` ```
@@ -37,14 +36,24 @@ Using jlog is straightforward:
#include <jlog.h> #include <jlog.h>
int main() { int main() {
jlog::info("This is barely useful information."); LOGLEVEL(jlog::severity::debug); // <- see jlog::severity for full list of log levels
jlog::error("Oops, something went wrong.");
INFO("This is barely useful information.");
DEBUG("Debugging Information");
VERBOSE("Yadda Yadda Yadda");
WARNING("Slight miscalculation!");
ERROR("Oops, something went wrong.");
FATAL("Unrecoverable Error!!!");
return 0; return 0;
} }
``` ```
## Output
![Should be sample output...](img.png)
## TODO ## TODO
* Custom Contexts: Allow users to specify custom logging contexts for better organization. * Custom Contexts: Allow users to specify custom logging contexts for better organization.

BIN
img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -4,106 +4,136 @@
#include <cstdint> #include <cstdint>
#include <format> #include <format>
#define ESC "\033[" #ifdef _WIN32
#include <windows.h>
#endif
#ifdef _WIN32
namespace jlog::ansi_escape_codes namespace jlog::ansi_escape_codes
{ {
static const std::string CURSOR_HOME = "\033[H"; const WORD FG_BLACK = 0;
const WORD FG_RED = FOREGROUND_RED;
const WORD FG_GREEN = FOREGROUND_GREEN;
const WORD FG_YELLOW = FOREGROUND_RED | FOREGROUND_GREEN;
const WORD FG_BLUE = FOREGROUND_BLUE;
const WORD FG_MAGENTA = FOREGROUND_RED | FOREGROUND_BLUE;
const WORD FG_CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE;
const WORD FG_WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
const WORD FG_DEFAULT = FG_WHITE;
static const std::string ERASE_SCREEN_AFTER_CURSOR = "\033[0J"; const WORD FG_BRIGHT_BLACK = 0 | FOREGROUND_INTENSITY;
static const std::string ERASE_SCREEN_BEFORE_CURSOR = "\033[1J"; const WORD FG_BRIGHT_RED = FOREGROUND_RED | FOREGROUND_INTENSITY;
static const std::string ERASE_SCREEN_ALL = "\033[2J"; const WORD FG_BRIGHT_GREEN = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
static const std::string ERASE_LINE_AFTER_CURSOR = "\033[0K"; const WORD FG_BRIGHT_YELLOW = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
static const std::string ERASE_LINE_BEFORE_CURSOR = "\033[1K"; const WORD FG_BRIGHT_BLUE = FOREGROUND_BLUE | FOREGROUND_INTENSITY;
static const std::string ERASE_LINE_ALL = "\033[2K"; const WORD FG_BRIGHT_MAGENTA = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
const WORD FG_BRIGHT_CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
const WORD FG_BRIGHT_WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
static const std::string RESET = "\033[0m"; inline void SetConsoleTextColor(WORD color) {
static const std::string BOLD = "\033[1m"; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
static const std::string DIM = "\033[2m"; }
}
#else
namespace jlog::ansi_escape_codes
{
inline static const std::string CURSOR_HOME = "\033[H";
inline static const std::string ERASE_SCREEN_AFTER_CURSOR = "\033[0J";
inline static const std::string ERASE_SCREEN_BEFORE_CURSOR = "\033[1J";
inline static const std::string ERASE_SCREEN_ALL = "\033[2J";
inline static const std::string ERASE_LINE_AFTER_CURSOR = "\033[0K";
inline static const std::string ERASE_LINE_BEFORE_CURSOR = "\033[1K";
inline static const std::string ERASE_LINE_ALL = "\033[2K";
inline static const std::string RESET = "\033[0m";
inline static const std::string BOLD = "\033[1m";
inline static const std::string DIM = "\033[2m";
/// These are some examples of private modes, which are not defined by the spec, but are implemented in most terminals. /// These are some examples of private modes, which are not defined by the spec, but are implemented in most terminals.
/// @see xterm control sequences for a more in-depth list. /// @see xterm control sequences for a more in-depth list.
/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html /// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
/// @note While these modes may be supported by most terminals, some may not work in multiplexers like tmux. /// @note While these modes may be supported by most terminals, some may not work in multiplexers like tmux.
static const std::string CURSOR_INVISIBLE = "\033[?25l"; inline static const std::string CURSOR_INVISIBLE = "\033[?25l";
static const std::string CURSOR_VISIBLE = "\033[?25h"; inline static const std::string CURSOR_VISIBLE = "\033[?25h";
static const std::string RESTORE_SCREEN = "\033[?47l"; inline static const std::string RESTORE_SCREEN = "\033[?47l";
static const std::string SAVE_SCREEN = "\033[?47h"; inline static const std::string SAVE_SCREEN = "\033[?47h";
static const std::string FG_BLACK = "\033[30m"; inline static const std::string FG_BLACK = "\033[30m";
static const std::string FG_RED = "\033[31m"; inline static const std::string FG_RED = "\033[31m";
static const std::string FG_GREEN = "\033[32m"; inline static const std::string FG_GREEN = "\033[32m";
static const std::string FG_YELLOW = "\033[33m"; inline static const std::string FG_YELLOW = "\033[33m";
static const std::string FG_BLUE = "\033[34m"; inline static const std::string FG_BLUE = "\033[34m";
static const std::string FG_MAGENTA = "\033[35m"; inline static const std::string FG_MAGENTA = "\033[35m";
static const std::string FG_CYAN = "\033[36m"; inline static const std::string FG_CYAN = "\033[36m";
static const std::string FG_WHITE = "\033[37m"; inline static const std::string FG_WHITE = "\033[37m";
static const std::string FG_DEFAULT = "\033[39m"; inline static const std::string FG_DEFAULT = "\033[39m";
static const std::string FG_BRIGHT_BLACK = "\033[90m"; inline static const std::string FG_BRIGHT_BLACK = "\033[90m";
static const std::string FG_BRIGHT_RED = "\033[91m"; inline static const std::string FG_BRIGHT_RED = "\033[91m";
static const std::string FG_BRIGHT_GREEN = "\033[92m"; inline static const std::string FG_BRIGHT_GREEN = "\033[92m";
static const std::string FG_BRIGHT_YELLOW = "\033[93m"; inline static const std::string FG_BRIGHT_YELLOW = "\033[93m";
static const std::string FG_BRIGHT_BLUE = "\033[94m"; inline static const std::string FG_BRIGHT_BLUE = "\033[94m";
static const std::string FG_BRIGHT_MAGENTA = "\033[95m"; inline static const std::string FG_BRIGHT_MAGENTA = "\033[95m";
static const std::string FG_BRIGHT_CYAN = "\033[96m"; inline static const std::string FG_BRIGHT_CYAN = "\033[96m";
static const std::string FG_BRIGHT_WHITE = "\033[97m"; inline static const std::string FG_BRIGHT_WHITE = "\033[97m";
static const std::string BG_BLACK = "\033[40m"; inline static const std::string BG_BLACK = "\033[40m";
static const std::string BG_RED = "\033[41m"; inline static const std::string BG_RED = "\033[41m";
static const std::string BG_GREEN = "\033[42m"; inline static const std::string BG_GREEN = "\033[42m";
static const std::string BG_YELLOW = "\033[43m"; inline static const std::string BG_YELLOW = "\033[43m";
static const std::string BG_BLUE = "\033[44m"; inline static const std::string BG_BLUE = "\033[44m";
static const std::string BG_MAGENTA = "\033[45m"; inline static const std::string BG_MAGENTA = "\033[45m";
static const std::string BG_CYAN = "\033[46m"; inline static const std::string BG_CYAN = "\033[46m";
static const std::string BG_WHITE = "\033[47m"; inline static const std::string BG_WHITE = "\033[47m";
static const std::string BG_DEFAULT = "\033[49m"; inline static const std::string BG_DEFAULT = "\033[49m";
static const std::string BG_BRIGHT_BLACK = "\033[100m"; inline static const std::string BG_BRIGHT_BLACK = "\033[100m";
static const std::string BG_BRIGHT_RED = "\033[101m"; inline static const std::string BG_BRIGHT_RED = "\033[101m";
static const std::string BG_BRIGHT_GREEN = "\033[102m"; inline static const std::string BG_BRIGHT_GREEN = "\033[102m";
static const std::string BG_BRIGHT_YELLOW = "\033[103m"; inline static const std::string BG_BRIGHT_YELLOW = "\033[103m";
static const std::string BG_BRIGHT_BLUE = "\033[104m"; inline static const std::string BG_BRIGHT_BLUE = "\033[104m";
static const std::string BG_BRIGHT_MAGENTA = "\033[105m"; inline static const std::string BG_BRIGHT_MAGENTA = "\033[105m";
static const std::string BG_BRIGHT_CYAN = "\033[106m"; inline static const std::string BG_BRIGHT_CYAN = "\033[106m";
static const std::string BG_BRIGHT_WHITE = "\033[107m"; inline static const std::string BG_BRIGHT_WHITE = "\033[107m";
std::string true_color(uint8_t r, uint8_t g, uint8_t b) inline std::string true_color(uint8_t r, uint8_t g, uint8_t b)
{ {
return std::format("\033[38;2;{};{};{}m", r, g, b); return std::format("\033[38;2;{};{};{}m", r, g, b);
} }
std::string cursor_to(int line, int col) inline std::string cursor_to(int line, int col)
{ {
return "";
} }
std::string cursor_up(int lines) inline std::string cursor_up(int lines)
{ {
return "";
} }
std::string cursor_down(int lines) inline std::string cursor_down(int lines)
{ {
return "";
} }
std::string cursor_left(int cols) inline std::string cursor_left(int cols)
{ {
return "";
} }
std::string cursor_right(int cols) inline std::string cursor_right(int cols)
{ {
return "";
} }
std::string cursor_to_col(int col) inline std::string cursor_to_col(int col)
{ {
return "";
} }
} }
#endif

View File

@@ -9,13 +9,23 @@
#include <format> #include <format>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <chrono>
#include <Event.h> #include <Event.h>
#include <fstream> #include <jlog/ansi_escape_codes.hpp>
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef __linux__
#define FUNCTION __PRETTY_FUNCTION__
#endif
#ifdef _WIN32
#define FUNCTION __FUNCSIG__
#endif
namespace jlog namespace jlog
{ {
enum class severity /*enum class severity : uint8_t
{ {
none, none,
verbose, verbose,
@@ -24,6 +34,19 @@ namespace jlog
error, error,
fatal fatal
}; };
*/
enum class severity : uint8_t
{
none,
warning,
error,
fatal,
verbose,
debug,
};
inline severity loglevel = severity::debug; // Default log level always debug
struct LogEntry struct LogEntry
{ {
@@ -32,31 +55,100 @@ namespace jlog
std::string timestamp; std::string timestamp;
}; };
static Event<LogEntry> on_log = Event<LogEntry>(); static Event<LogEntry> on_log = Event<LogEntry>();
std::vector<LogEntry> log_history; inline std::vector<LogEntry> log_history;
struct token struct token
{ {
std::string colorCode = ""; #ifdef _WIN32
WORD colorCode = ansi_escape_codes::FG_DEFAULT;
#else
std::string colorCode = ansi_escape_codes::RESET;
#endif
std::string content = ""; std::string content = "";
std::string delimiter = "[]"; std::string delimiter = "[]";
}; };
std::string get_timestamp();
void log_to_console(const std::string& message);
void log_to_file(const std::string& message);
void log(std::vector<token> tokens); void log(std::vector<token> tokens);
void direct (const std::string& message);
void info(const std::string& message); void info(const std::string& message);
void sinfo(const std::string& message);
void usinfo(const std::string& message);
void verbose(const std::string& message); void verbose(const std::string& message);
void sverbose(const std::string& message);
void usverbose(const std::string& message);
void debug(const std::string& message); void debug(const std::string& message);
void sdebug(const std::string& message);
void usdebug(const std::string& message);
void warning(const std::string& message); void warning(const std::string& message);
void swarning(const std::string& message);
void uswarning(const std::string& message);
void error(const std::string& message); void error(const std::string& message);
void serror(const std::string& message);
void userror(const std::string& message);
void fatal(const std::string& message); void fatal(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);
void sinfo_spec(const std::string& message, const std::string& func, const std::string& file, int line);
void usinfo_spec(const std::string& message, 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);
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);
void sdebug_spec(const std::string& message, const std::string& func, const std::string& file, int line);
void usdebug_spec(const std::string& message, 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);
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);
void serror_spec(const std::string& message, const std::string& func, const std::string& file, int line);
void userror_spec(const std::string& message, 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);
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);
} }
#define INFO(i) if (jlog::loglevel >= jlog::severity::none) { jlog::info_spec(i, FUNCTION, __FILE__, __LINE__); };
#define SINFO(i) if (jlog::loglevel >= jlog::severity::none) { jlog::sinfo_spec(i, FUNCTION, __FILE__, __LINE__); };
#define USINFO(i) if (jlog::loglevel >= jlog::severity::none) { jlog::usinfo_spec(i, FUNCTION, __FILE__, __LINE__); };
#define VERBOSE(i) if (jlog::loglevel >= jlog::severity::verbose) { jlog::verbose_spec(i, FUNCTION, __FILE__, __LINE__); };
#define SVERBOSE(i) if (jlog::loglevel >= jlog::severity::verbose) { jlog::sverbose_spec(i, FUNCTION, __FILE__, __LINE__); };
#define USVERBOSE(i) if (jlog::loglevel >= jlog::severity::verbose) { jlog::usverbose_spec(i, FUNCTION, __FILE__, __LINE__); };
#define DEBUG(i) if (jlog::loglevel >= jlog::severity::debug) { jlog::debug_spec(i, FUNCTION, __FILE__, __LINE__); };
#define SDEBUG(i) if (jlog::loglevel >= jlog::severity::debug) { jlog::sdebug_spec(i, FUNCTION, __FILE__, __LINE__); };
#define USDEBUG(i) if (jlog::loglevel >= jlog::severity::debug) { jlog::usdebug_spec(i, FUNCTION, __FILE__, __LINE__); };
#define WARNING(i) if (jlog::loglevel >= jlog::severity::warning) { jlog::warning_spec(i, FUNCTION, __FILE__, __LINE__); };
#define SWARNING(i) if (jlog::loglevel >= jlog::severity::warning) { jlog::swarning_spec(i, FUNCTION, __FILE__, __LINE__); };
#define USWARNING(i) if (jlog::loglevel >= jlog::severity::warning) { jlog::uswarning_spec(i, FUNCTION, __FILE__, __LINE__); };
#define ERROR(i) if (jlog::loglevel >= jlog::severity::error) { jlog::error_spec(i, FUNCTION, __FILE__, __LINE__); };
#define SERROR(i) if (jlog::loglevel >= jlog::severity::error) { jlog::serror_spec(i, FUNCTION, __FILE__, __LINE__); };
#define USERROR(i) if (jlog::loglevel >= jlog::severity::error) { jlog::userror_spec(i, FUNCTION, __FILE__, __LINE__); };
#define FATAL(i) if (jlog::loglevel >= jlog::severity::fatal) { jlog::fatal_spec(i, FUNCTION, __FILE__, __LINE__); };
#define SFATAL(i) if (jlog::loglevel >= jlog::severity::fatal) { jlog::sfatal_spec(i, FUNCTION, __FILE__, __LINE__); };
#define USFATAL(i) if (jlog::loglevel >= jlog::severity::fatal) { jlog::usfatal_spec(i, FUNCTION, __FILE__, __LINE__); };
//LINFO
#define LOGLEVEL(i) jlog::loglevel = i;

View File

@@ -1,15 +1,39 @@
#include <jlog/ansi_escape_codes.hpp>
#include <jlog/jlog.hpp> #include <jlog/jlog.hpp>
int main() int main()
{ {
jlog::info("Do the needful!"); LOGLEVEL(jlog::severity::debug); // <- see jlog::severity for full list of log levels
jlog::debug("Debugging Message 123");
jlog::error("Big problem!"); INFO("This is barely useful information.");
jlog::verbose("Irrelevant message..."); DEBUG("Debugging Information");
jlog::warning("Our software suite is only supported on C++20! Get with it grampa."); VERBOSE("Yadda Yadda Yadda");
jlog::fatal("FUCK BRO"); WARNING("Slight miscalculation!");
ERROR("Oops, something went wrong.");
FATAL("Unrecoverable Error!!!");
SINFO("This is even less useful information.");
SDEBUG("Shorter Debugging Information");
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 :(
#ifdef _WIN32
extern "C" {
int wmain(int argc, wchar_t* argv[]) {
return main();
}
}
#endif

View File

@@ -1,112 +0,0 @@
#include <source_location>
#include <jlog/ansi_escape_codes.hpp>
#include <jlog/jlog.hpp>
#include <string>
namespace jlog {
static std::string get_timestamp();
static void log_to_console(const std::string& message);
static void log_to_file(const std::string& message);
std::string get_timestamp()
{
using namespace std::chrono;
auto const timestamp = current_zone()->to_local(system_clock::now());
auto dp = floor<days>(timestamp);
year_month_day ymd{floor<days>(timestamp)};
hh_mm_ss time{floor<milliseconds>(timestamp-dp)};
auto y = ymd.year();
auto m = ymd.month();
auto d = ymd.day();
auto h = time.hours();
auto M = time.minutes();
auto s = time.seconds();
auto ms = time.subseconds();
return std::format("{}-{}-{} {}:{}:{}.{}", y, m, d, h.count(), M.count(), s.count(), ms.count());
}
void log_to_console(const std::string &message)
{
std::cout << message;
}
void log_to_file(const std::string &message)
{
std::ofstream latest_log("latest.log", std::ios_base::app);
latest_log << message;
latest_log.close();
}
void log(std::vector<token> tokens) {
for (token t : tokens) {
if (t.delimiter != "") {
log_to_console(std::format("{}{}{}{}{} ", t.colorCode, t.delimiter[0], t.content, t.delimiter[1], ansi_escape_codes::RESET));
log_to_file(std::format("{}{}{} ", t.delimiter[0], t.content, t.delimiter[1]));
} else {
log_to_console(std::format("{}{}{} ", t.colorCode, t.content, ansi_escape_codes::RESET));
log_to_file(t.content + " ");
}
}
log_to_console("\n");
log_to_file("\n");
}
void direct(const std::string &message) { log({{.content = message, .delimiter=""}});}
void info(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({timestamp, 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 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 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 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 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 = ""};
auto trace = token{.content = __PRETTY_FUNCTION__};
auto source = std::source_location::current();
auto file = token{.content = std::format("{}:{}", __FILE__, __LINE__)};
log({timestamp, trace, file, severity, content});
}
}

363
src/jlog/linux/jlog.cpp Normal file
View File

@@ -0,0 +1,363 @@
#include <source_location>
#include <jlog/ansi_escape_codes.hpp>
#include <jlog/jlog.hpp>
#include <string>
#include <fstream>
namespace jlog {
std::string get_timestamp()
{
using namespace std::chrono;
auto const timestamp = current_zone()->to_local(system_clock::now());
auto dp = floor<days>(timestamp);
year_month_day ymd{floor<days>(timestamp)};
hh_mm_ss time{floor<milliseconds>(timestamp-dp)};
auto y = ymd.year();
auto m = ymd.month();
auto d = ymd.day();
auto h = time.hours();
auto M = time.minutes();
auto s = time.seconds();
auto ms = time.subseconds();
return std::format("{}-{}-{} {}:{}:{}.{}", y, m, d, h.count(), M.count(), s.count(), ms.count());
}
void log_to_console(const std::string &message)
{
std::cout << message;
}
void log_to_file(const std::string &message)
{
std::ofstream latest_log("latest.log", std::ios_base::app);
latest_log << message;
latest_log.close();
}
void log(std::vector<token> tokens) {
for (token t : tokens) {
if (t.delimiter != "") {
log_to_console(std::format("{}{}{}{}{} ", t.colorCode, t.delimiter[0], t.content, t.delimiter[1], ansi_escape_codes::RESET));
log_to_file(std::format("{}{}{} ", t.delimiter[0], t.content, t.delimiter[1]));
} else {
log_to_console(std::format("{}{}{} ", t.colorCode, t.content, ansi_escape_codes::RESET));
log_to_file(t.content + " ");
}
}
log_to_console("\n");
log_to_file("\n");
}
void direct(const std::string &message) { log({{.content = message, .delimiter=""}});}
void info(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({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 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 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 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,
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 filedata = token{.content = std::format("{}:{}", file, line)};
//log({trace, filedata, severity, content});
log({severity, content});
}
void verbose_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_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 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 = 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 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 = 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,
int line) {
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 = 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 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 = 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 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 = func};
//auto filedata = token{.content = std::format("{}:{}", file, line)};
log({severity, content});
}
void warning_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_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,
int line) {
//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 = 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 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 = 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,
int line) {
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 = 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 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 = 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 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 = func};
//auto filedata = token{.content = std::format("{}:{}", file, line)};
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});
}
}

312
src/jlog/windows/jlog.cpp Normal file
View File

@@ -0,0 +1,312 @@
#include <source_location>
#include <jlog/ansi_escape_codes.hpp>
#include <jlog/jlog.hpp>
#include <string>
#include <chrono>
#include <fstream>
#include <iostream>
#include <windows.h>
namespace jlog {
std::string get_timestamp() {
using namespace std::chrono;
auto const timestamp = current_zone()->to_local(system_clock::now());
auto dp = floor<days>(timestamp);
year_month_day ymd{floor<days>(timestamp)};
hh_mm_ss time{floor<milliseconds>(timestamp - dp)};
auto y = ymd.year();
auto m = ymd.month();
auto d = ymd.day();
auto h = time.hours();
auto M = time.minutes();
auto s = time.seconds();
auto ms = time.subseconds();
return std::format("{}-{}-{} {}:{}:{}.{}", y, m, d, h.count(), M.count(), s.count(), ms.count());
}
void log_to_console(const std::string& message) {
std::cout << message;
}
void log_to_file(const std::string& message) {
std::ofstream latest_log("latest.log", std::ios_base::app);
latest_log << message;
latest_log.close();
}
void log(std::vector<token> tokens) {
for (const token& t : tokens) {
if (!t.delimiter.empty()) {
ansi_escape_codes::SetConsoleTextColor(t.colorCode);
log_to_console(std::string(1, t.delimiter[0]) + t.content + std::string(1, t.delimiter[1]) + " ");
log_to_file(std::string(1, t.delimiter[0]) + t.content + std::string(1, t.delimiter[1]) + " ");
} else {
ansi_escape_codes::SetConsoleTextColor(t.colorCode);
log_to_console(t.content + " ");
log_to_file(t.content + " ");
}
}
ansi_escape_codes::SetConsoleTextColor(ansi_escape_codes::FG_DEFAULT);
log_to_console("\n");
log_to_file("\n");
}
void direct(const std::string& message) {
log({{.content = message, .delimiter = ""}});
}
void info(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 = ""};
log({timestamp, severity, content});
}
void sinfo(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
void usinfo(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_WHITE, .content = "INFO"};
auto content = token{.content = message, .delimiter = ""};
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 = ""};
log({timestamp, severity, content});
}
void sverbose(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_CYAN, .content = "VERBOSE"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
void usverbose(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_CYAN, .content = "VERBOSE"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
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 = ""};
log({timestamp, severity, content});
}
void sdebug(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_GREEN, .content = "DEBUG"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
void usdebug(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_GREEN, .content = "DEBUG"};
auto content = token{.content = message, .delimiter = ""};
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 = ""};
log({timestamp, severity, content});
}
void swarning(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_YELLOW, .content = "WARNING"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
void uswarning(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_YELLOW, .content = "WARNING"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
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 = ""};
log({timestamp, severity, content});
}
void serror(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_RED, .content = "ERROR"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
void userror(const std::string& message) {
auto severity = token{.colorCode = ansi_escape_codes::FG_RED, .content = "ERROR"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
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 sfatal(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 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 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 = ansi_escape_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 = ansi_escape_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 = get_timestamp()};
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({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 = 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({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 = ansi_escape_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 = get_timestamp()};
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({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 = 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, int line) {
auto severity = token{.colorCode = ansi_escape_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 = get_timestamp()};
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, int line) {
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({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 = ansi_escape_codes::FG_YELLOW, .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 = get_timestamp()};
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({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 = 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, int line) {
auto severity = token{.colorCode = ansi_escape_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 = 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 severity = token{.colorCode = ansi_escape_codes::FG_BRIGHT_RED, .content = "FATAL"};
auto content = token{.content = message, .delimiter = ""};
log({severity, content});
}
}