Compare commits
7 Commits
Prerelease
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
|
80d9bcd240 | ||
2799c918b8 | |||
a86e70a055 | |||
3cf70f5f4f | |||
3a28d4e43b | |||
e5cfd25fcc | |||
b0793828f6 |
@@ -48,7 +48,7 @@ install(FILES ${jlog_HEADERS} DESTINATION include/${PROJECT_NAME})
|
||||
|
||||
#add_subdirectory(tests)
|
||||
|
||||
target_link_libraries(jlog PUBLIC Event)
|
||||
target_link_libraries(jlog PRIVATE Event)
|
||||
|
||||
add_executable(LoggerDemo main.cpp)
|
||||
target_link_libraries(LoggerDemo PUBLIC ${PROJECT_NAME})
|
||||
|
@@ -15,7 +15,6 @@ jlog is a C++ library for logging to file, console, and event callbacks.
|
||||
## Installation
|
||||
|
||||
Include this repository as a CPM dependency, and link against the library.
|
||||
(TODO: Show the relevant CMake script lines.)
|
||||
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
@@ -37,6 +36,8 @@ Using jlog is straightforward:
|
||||
#include <jlog.h>
|
||||
|
||||
int main() {
|
||||
LOGLEVEL(jlog::severity::debug); // <- see jlog::severity for full list of log levels
|
||||
|
||||
INFO("This is barely useful information.");
|
||||
DEBUG("Debugging Information");
|
||||
VERBOSE("Yadda Yadda Yadda");
|
||||
|
@@ -37,101 +37,101 @@ namespace jlog::ansi_escape_codes
|
||||
#else
|
||||
namespace jlog::ansi_escape_codes
|
||||
{
|
||||
static const std::string CURSOR_HOME = "\033[H";
|
||||
inline static const std::string CURSOR_HOME = "\033[H";
|
||||
|
||||
static const std::string ERASE_SCREEN_AFTER_CURSOR = "\033[0J";
|
||||
static const std::string ERASE_SCREEN_BEFORE_CURSOR = "\033[1J";
|
||||
static const std::string ERASE_SCREEN_ALL = "\033[2J";
|
||||
static const std::string ERASE_LINE_AFTER_CURSOR = "\033[0K";
|
||||
static const std::string ERASE_LINE_BEFORE_CURSOR = "\033[1K";
|
||||
static const std::string ERASE_LINE_ALL = "\033[2K";
|
||||
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";
|
||||
|
||||
static const std::string RESET = "\033[0m";
|
||||
static const std::string BOLD = "\033[1m";
|
||||
static const std::string DIM = "\033[2m";
|
||||
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.
|
||||
/// @see xterm control sequences for a more in-depth list.
|
||||
/// 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.
|
||||
|
||||
static const std::string CURSOR_INVISIBLE = "\033[?25l";
|
||||
static const std::string CURSOR_VISIBLE = "\033[?25h";
|
||||
static const std::string RESTORE_SCREEN = "\033[?47l";
|
||||
static const std::string SAVE_SCREEN = "\033[?47h";
|
||||
inline static const std::string CURSOR_INVISIBLE = "\033[?25l";
|
||||
inline static const std::string CURSOR_VISIBLE = "\033[?25h";
|
||||
inline static const std::string RESTORE_SCREEN = "\033[?47l";
|
||||
inline static const std::string SAVE_SCREEN = "\033[?47h";
|
||||
|
||||
|
||||
static const std::string FG_BLACK = "\033[30m";
|
||||
static const std::string FG_RED = "\033[31m";
|
||||
static const std::string FG_GREEN = "\033[32m";
|
||||
static const std::string FG_YELLOW = "\033[33m";
|
||||
static const std::string FG_BLUE = "\033[34m";
|
||||
static const std::string FG_MAGENTA = "\033[35m";
|
||||
static const std::string FG_CYAN = "\033[36m";
|
||||
static const std::string FG_WHITE = "\033[37m";
|
||||
static const std::string FG_DEFAULT = "\033[39m";
|
||||
inline static const std::string FG_BLACK = "\033[30m";
|
||||
inline static const std::string FG_RED = "\033[31m";
|
||||
inline static const std::string FG_GREEN = "\033[32m";
|
||||
inline static const std::string FG_YELLOW = "\033[33m";
|
||||
inline static const std::string FG_BLUE = "\033[34m";
|
||||
inline static const std::string FG_MAGENTA = "\033[35m";
|
||||
inline static const std::string FG_CYAN = "\033[36m";
|
||||
inline static const std::string FG_WHITE = "\033[37m";
|
||||
inline static const std::string FG_DEFAULT = "\033[39m";
|
||||
|
||||
|
||||
static const std::string FG_BRIGHT_BLACK = "\033[90m";
|
||||
static const std::string FG_BRIGHT_RED = "\033[91m";
|
||||
static const std::string FG_BRIGHT_GREEN = "\033[92m";
|
||||
static const std::string FG_BRIGHT_YELLOW = "\033[93m";
|
||||
static const std::string FG_BRIGHT_BLUE = "\033[94m";
|
||||
static const std::string FG_BRIGHT_MAGENTA = "\033[95m";
|
||||
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_BLACK = "\033[90m";
|
||||
inline static const std::string FG_BRIGHT_RED = "\033[91m";
|
||||
inline static const std::string FG_BRIGHT_GREEN = "\033[92m";
|
||||
inline static const std::string FG_BRIGHT_YELLOW = "\033[93m";
|
||||
inline static const std::string FG_BRIGHT_BLUE = "\033[94m";
|
||||
inline static const std::string FG_BRIGHT_MAGENTA = "\033[95m";
|
||||
inline static const std::string FG_BRIGHT_CYAN = "\033[96m";
|
||||
inline static const std::string FG_BRIGHT_WHITE = "\033[97m";
|
||||
|
||||
|
||||
static const std::string BG_BLACK = "\033[40m";
|
||||
static const std::string BG_RED = "\033[41m";
|
||||
static const std::string BG_GREEN = "\033[42m";
|
||||
static const std::string BG_YELLOW = "\033[43m";
|
||||
static const std::string BG_BLUE = "\033[44m";
|
||||
static const std::string BG_MAGENTA = "\033[45m";
|
||||
static const std::string BG_CYAN = "\033[46m";
|
||||
static const std::string BG_WHITE = "\033[47m";
|
||||
static const std::string BG_DEFAULT = "\033[49m";
|
||||
inline static const std::string BG_BLACK = "\033[40m";
|
||||
inline static const std::string BG_RED = "\033[41m";
|
||||
inline static const std::string BG_GREEN = "\033[42m";
|
||||
inline static const std::string BG_YELLOW = "\033[43m";
|
||||
inline static const std::string BG_BLUE = "\033[44m";
|
||||
inline static const std::string BG_MAGENTA = "\033[45m";
|
||||
inline static const std::string BG_CYAN = "\033[46m";
|
||||
inline static const std::string BG_WHITE = "\033[47m";
|
||||
inline static const std::string BG_DEFAULT = "\033[49m";
|
||||
|
||||
static const std::string BG_BRIGHT_BLACK = "\033[100m";
|
||||
static const std::string BG_BRIGHT_RED = "\033[101m";
|
||||
static const std::string BG_BRIGHT_GREEN = "\033[102m";
|
||||
static const std::string BG_BRIGHT_YELLOW = "\033[103m";
|
||||
static const std::string BG_BRIGHT_BLUE = "\033[104m";
|
||||
static const std::string BG_BRIGHT_MAGENTA = "\033[105m";
|
||||
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_BLACK = "\033[100m";
|
||||
inline static const std::string BG_BRIGHT_RED = "\033[101m";
|
||||
inline static const std::string BG_BRIGHT_GREEN = "\033[102m";
|
||||
inline static const std::string BG_BRIGHT_YELLOW = "\033[103m";
|
||||
inline static const std::string BG_BRIGHT_BLUE = "\033[104m";
|
||||
inline static const std::string BG_BRIGHT_MAGENTA = "\033[105m";
|
||||
inline static const std::string BG_BRIGHT_CYAN = "\033[106m";
|
||||
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);
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@
|
||||
|
||||
namespace jlog
|
||||
{
|
||||
enum class severity
|
||||
/*enum class severity : uint8_t
|
||||
{
|
||||
none,
|
||||
verbose,
|
||||
@@ -34,6 +34,19 @@ namespace jlog
|
||||
error,
|
||||
fatal
|
||||
};
|
||||
*/
|
||||
|
||||
enum class severity : uint8_t
|
||||
{
|
||||
none,
|
||||
warning,
|
||||
error,
|
||||
fatal,
|
||||
verbose,
|
||||
debug,
|
||||
};
|
||||
|
||||
inline severity loglevel = severity::debug; // Default log level always debug
|
||||
|
||||
struct LogEntry
|
||||
{
|
||||
@@ -112,26 +125,30 @@ namespace jlog
|
||||
void usfatal_spec(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 SINFO(i) jlog::sinfo_spec(i, FUNCTION, __FILE__, __LINE__);
|
||||
#define USINFO(i) jlog::usinfo_spec(i, FUNCTION, __FILE__, __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) jlog::verbose_spec(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 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) jlog::debug_spec(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 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) jlog::warning_spec(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 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) jlog::error_spec(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 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) jlog::fatal_spec(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 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;
|
Reference in New Issue
Block a user