Compare commits
6 Commits
Prerelease
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
f0ccdf00c0 | |||
|
9f0ccef302 | ||
c5d3f7dc82 | |||
aaa7318672 | |||
95f2c761c7 | |||
|
16d1eaa1ee |
@@ -14,16 +14,16 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|||||||
|
|
||||||
include(cmake/CPM.cmake)
|
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")
|
||||||
|
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
file(GLOB_RECURSE jlog_SRC "src/jlog/linux/*.c" "src/jlog/linux/*.cpp")
|
file(GLOB_RECURSE jlog_SRC "src/jlog/linux/*.c" "src/jlog/linux/*.cpp" "src/jlog/shared/*.c" "src/jlog/shared/*.cpp")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
file(GLOB_RECURSE jlog_SRC "src/jlog/windows/*.c" "src/jlog/windows/*.cpp")
|
file(GLOB_RECURSE jlog_SRC "src/jlog/windows/*.c" "src/jlog/windows/*.cpp" "src/jlog/shared/*.c" "src/jlog/shared/*.cpp")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories("include")
|
include_directories("include")
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
@@ -51,4 +51,4 @@ install(FILES ${jlog_HEADERS} DESTINATION include/${PROJECT_NAME})
|
|||||||
target_link_libraries(jlog PRIVATE Event)
|
target_link_libraries(jlog PRIVATE Event)
|
||||||
|
|
||||||
add_executable(LoggerDemo main.cpp)
|
add_executable(LoggerDemo main.cpp)
|
||||||
target_link_libraries(LoggerDemo PUBLIC ${PROJECT_NAME})
|
target_link_libraries(LoggerDemo PUBLIC jlog)
|
||||||
|
@@ -11,6 +11,7 @@ jlog is a C++ library for logging to file, console, and event callbacks.
|
|||||||
* Color Output
|
* Color Output
|
||||||
* Logs to file AND console!
|
* Logs to file AND console!
|
||||||
* Idiomatic Event callback for hooking into your game engine gui!
|
* Idiomatic Event callback for hooking into your game engine gui!
|
||||||
|
* GCC and MSVC support
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ Include this repository as a CPM dependency, and link against the library.
|
|||||||
```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)
|
||||||
@@ -29,6 +30,7 @@ target_link_libraries(YourProgram ... jlog)
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Usage
|
||||||
Using jlog is straightforward:
|
Using jlog is straightforward:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -58,12 +60,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
|
||||||
|
|
||||||
|
@@ -4,37 +4,6 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
namespace jlog::ansi_escape_codes
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
const WORD FG_BRIGHT_BLACK = 0 | FOREGROUND_INTENSITY;
|
|
||||||
const WORD FG_BRIGHT_RED = FOREGROUND_RED | FOREGROUND_INTENSITY;
|
|
||||||
const WORD FG_BRIGHT_GREEN = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
|
||||||
const WORD FG_BRIGHT_YELLOW = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
|
||||||
const WORD FG_BRIGHT_BLUE = FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
|
||||||
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;
|
|
||||||
|
|
||||||
inline void SetConsoleTextColor(WORD color) {
|
|
||||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
namespace jlog::ansi_escape_codes
|
namespace jlog::ansi_escape_codes
|
||||||
{
|
{
|
||||||
inline static const std::string CURSOR_HOME = "\033[H";
|
inline static const std::string CURSOR_HOME = "\033[H";
|
||||||
@@ -136,4 +105,4 @@ namespace jlog::ansi_escape_codes
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
52
include/jlog/color_codes.hpp
Normal file
52
include/jlog/color_codes.hpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <jlog/ansi_escape_codes.hpp>
|
||||||
|
#include <jlog/nt_color_codes.hpp>
|
||||||
|
|
||||||
|
// Platform independent color code mapping
|
||||||
|
struct colorcode
|
||||||
|
{
|
||||||
|
std::string ansi_code;
|
||||||
|
WORD nt_code;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace jlog::color_codes
|
||||||
|
{
|
||||||
|
static const colorcode FG_BLACK {ansi_escape_codes::FG_BLACK, nt_color_codes::FG_BLACK };
|
||||||
|
static const colorcode FG_RED {ansi_escape_codes::FG_RED, nt_color_codes::FG_RED };
|
||||||
|
static const colorcode FG_GREEN {ansi_escape_codes::FG_GREEN, nt_color_codes::FG_GREEN };
|
||||||
|
static const colorcode FG_YELLOW {ansi_escape_codes::FG_YELLOW, nt_color_codes::FG_YELLOW };
|
||||||
|
static const colorcode FG_BLUE {ansi_escape_codes::FG_BLUE, nt_color_codes::FG_BLUE };
|
||||||
|
static const colorcode FG_MAGENTA {ansi_escape_codes::FG_MAGENTA, nt_color_codes::FG_MAGENTA };
|
||||||
|
static const colorcode FG_CYAN {ansi_escape_codes::FG_CYAN, nt_color_codes::FG_CYAN };
|
||||||
|
static const colorcode FG_WHITE {ansi_escape_codes::FG_WHITE, nt_color_codes::FG_WHITE };
|
||||||
|
static const colorcode FG_DEFAULT {ansi_escape_codes::FG_DEFAULT, nt_color_codes::FG_DEFAULT };
|
||||||
|
|
||||||
|
static const colorcode FG_BRIGHT_BLACK {ansi_escape_codes::FG_BRIGHT_BLACK, nt_color_codes::FG_BRIGHT_BLACK};
|
||||||
|
static const colorcode FG_BRIGHT_RED {ansi_escape_codes::FG_BRIGHT_RED, nt_color_codes::FG_BRIGHT_RED};
|
||||||
|
static const colorcode FG_BRIGHT_GREEN {ansi_escape_codes::FG_BRIGHT_GREEN, nt_color_codes::FG_BRIGHT_GREEN};
|
||||||
|
static const colorcode FG_BRIGHT_YELLOW {ansi_escape_codes::FG_BRIGHT_YELLOW, nt_color_codes::FG_BRIGHT_YELLOW};
|
||||||
|
static const colorcode FG_BRIGHT_BLUE {ansi_escape_codes::FG_BRIGHT_MAGENTA, nt_color_codes::FG_BRIGHT_MAGENTA};
|
||||||
|
static const colorcode FG_BRIGHT_MAGENTA {ansi_escape_codes::FG_BRIGHT_MAGENTA, nt_color_codes::FG_BRIGHT_MAGENTA};
|
||||||
|
static const colorcode FG_BRIGHT_CYAN {ansi_escape_codes::FG_BRIGHT_CYAN, nt_color_codes::FG_BRIGHT_CYAN};
|
||||||
|
static const colorcode FG_BRIGHT_WHITE {ansi_escape_codes::FG_BRIGHT_WHITE, nt_color_codes::FG_BRIGHT_WHITE};
|
||||||
|
|
||||||
|
static const colorcode BG_BLACK {ansi_escape_codes::BG_BLACK, nt_color_codes::BG_BLACK};
|
||||||
|
static const colorcode BG_RED {ansi_escape_codes::BG_RED, nt_color_codes::BG_RED};
|
||||||
|
static const colorcode BG_GREEN {ansi_escape_codes::BG_GREEN, nt_color_codes::BG_GREEN};
|
||||||
|
static const colorcode BG_YELLOW {ansi_escape_codes::BG_YELLOW, nt_color_codes::BG_YELLOW};
|
||||||
|
static const colorcode BG_BLUE {ansi_escape_codes::BG_BLUE, nt_color_codes::BG_BLUE};
|
||||||
|
static const colorcode BG_MAGENTA {ansi_escape_codes::BG_MAGENTA, nt_color_codes::BG_MAGENTA};
|
||||||
|
static const colorcode BG_CYAN {ansi_escape_codes::BG_CYAN, nt_color_codes::BG_CYAN};
|
||||||
|
static const colorcode BG_WHITE {ansi_escape_codes::BG_WHITE, nt_color_codes::BG_WHITE};
|
||||||
|
static const colorcode BG_DEFAULT {ansi_escape_codes::BG_DEFAULT, nt_color_codes::BG_DEFAULT};
|
||||||
|
|
||||||
|
static const colorcode BG_BRIGHT_BLACK {ansi_escape_codes::BG_BRIGHT_BLACK, nt_color_codes::BG_BRIGHT_BLACK};
|
||||||
|
static const colorcode BG_BRIGHT_RED {ansi_escape_codes::BG_BRIGHT_RED, nt_color_codes::BG_BRIGHT_RED};
|
||||||
|
static const colorcode BG_BRIGHT_GREEN {ansi_escape_codes::BG_BRIGHT_GREEN, nt_color_codes::BG_BRIGHT_GREEN};
|
||||||
|
static const colorcode BG_BRIGHT_YELLOW {ansi_escape_codes::BG_BRIGHT_YELLOW, nt_color_codes::BG_BRIGHT_YELLOW};
|
||||||
|
static const colorcode BG_BRIGHT_BLUE {ansi_escape_codes::BG_BRIGHT_BLUE, nt_color_codes::BG_BRIGHT_BLUE};
|
||||||
|
static const colorcode BG_BRIGHT_MAGENTA {ansi_escape_codes::BG_BRIGHT_MAGENTA, nt_color_codes::BG_BRIGHT_MAGENTA};
|
||||||
|
static const colorcode BG_BRIGHT_CYAN {ansi_escape_codes::BG_BRIGHT_CYAN, nt_color_codes::BG_BRIGHT_CYAN};
|
||||||
|
static const colorcode BG_BRIGHT_WHITE {ansi_escape_codes::BG_BRIGHT_WHITE, nt_color_codes::BG_BRIGHT_WHITE};
|
||||||
|
}
|
@@ -8,12 +8,8 @@
|
|||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
#include <Event.h>
|
#include <Event.h>
|
||||||
#include <jlog/ansi_escape_codes.hpp>
|
#include <jlog/color_codes.hpp>
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define FUNCTION __PRETTY_FUNCTION__
|
#define FUNCTION __PRETTY_FUNCTION__
|
||||||
@@ -25,17 +21,6 @@
|
|||||||
|
|
||||||
namespace jlog
|
namespace jlog
|
||||||
{
|
{
|
||||||
/*enum class severity : uint8_t
|
|
||||||
{
|
|
||||||
none,
|
|
||||||
verbose,
|
|
||||||
debug,
|
|
||||||
warning,
|
|
||||||
error,
|
|
||||||
fatal
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum class severity : uint8_t
|
enum class severity : uint8_t
|
||||||
{
|
{
|
||||||
none,
|
none,
|
||||||
@@ -61,11 +46,7 @@ namespace jlog
|
|||||||
|
|
||||||
struct token
|
struct token
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
colorcode colorCode = color_codes::FG_DEFAULT;
|
||||||
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 = "[]";
|
||||||
};
|
};
|
||||||
@@ -76,79 +57,86 @@ 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 colorcode& severity_cc = color_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 colorcode& severity_cc = color_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) if (jlog::loglevel >= jlog::severity::none) { 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) 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 VERBOSE(i) if (jlog::loglevel >= jlog::severity::verbose) { jlog::log(jlog::verbose_detailed_format(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 DEBUG(i) if (jlog::loglevel >= jlog::severity::debug) { jlog::log(jlog::debug_detailed_format(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 WARNING(i) if (jlog::loglevel >= jlog::severity::warning) { jlog::log(jlog::warning_detailed_format(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 ERROR(i) if (jlog::loglevel >= jlog::severity::error) { jlog::log(jlog::error_detailed_format(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 FATAL(i) if (jlog::loglevel >= jlog::severity::fatal) { jlog::log(jlog::fatal_detailed_format(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;
|
||||||
|
|
||||||
#define LOGLEVEL(i) jlog::loglevel = i;
|
|
55
include/jlog/nt_color_codes.hpp
Normal file
55
include/jlog/nt_color_codes.hpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// NT color codes taken from windows.h / consoleapi2.h
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WORD
|
||||||
|
#define WORD short
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace jlog::nt_color_codes
|
||||||
|
{
|
||||||
|
const WORD FG_BLACK = 0x0000;
|
||||||
|
const WORD FG_BLUE = 0x0001;
|
||||||
|
const WORD FG_GREEN = 0x0002;
|
||||||
|
const WORD FG_RED = 0x0004;
|
||||||
|
|
||||||
|
const WORD FG_YELLOW = FG_RED | FG_GREEN;
|
||||||
|
|
||||||
|
const WORD FG_MAGENTA = FG_RED | FG_BLUE;
|
||||||
|
const WORD FG_CYAN = FG_GREEN | FG_BLUE;
|
||||||
|
const WORD FG_WHITE = FG_RED | FG_GREEN | FG_BLUE;
|
||||||
|
const WORD FG_DEFAULT = FG_WHITE;
|
||||||
|
|
||||||
|
const WORD FG_BRIGHT_BLACK = 0 | 0x0008;
|
||||||
|
const WORD FG_BRIGHT_RED = FG_RED | 0x0008;
|
||||||
|
const WORD FG_BRIGHT_GREEN = FG_GREEN | 0x0008;
|
||||||
|
const WORD FG_BRIGHT_YELLOW = FG_RED | FG_GREEN | 0x0008;
|
||||||
|
const WORD FG_BRIGHT_BLUE = FG_BLUE | 0x0008;
|
||||||
|
const WORD FG_BRIGHT_MAGENTA = FG_RED | FG_BLUE | 0x0008;
|
||||||
|
const WORD FG_BRIGHT_CYAN = FG_GREEN | FG_BLUE | 0x0008;
|
||||||
|
const WORD FG_BRIGHT_WHITE = FG_RED | FG_GREEN | FG_BLUE | 0x0008;
|
||||||
|
|
||||||
|
|
||||||
|
const WORD BG_BLACK = 0x0000;
|
||||||
|
const WORD BG_BLUE = 0x0010;
|
||||||
|
const WORD BG_GREEN = 0x0020;
|
||||||
|
const WORD BG_RED = 0x0040;
|
||||||
|
const WORD BG_YELLOW = BG_RED | BG_GREEN;
|
||||||
|
const WORD BG_MAGENTA = BG_RED | BG_BLUE;
|
||||||
|
const WORD BG_CYAN = BG_GREEN | BG_BLUE;
|
||||||
|
const WORD BG_WHITE = BG_RED | BG_GREEN | BG_BLUE;
|
||||||
|
const WORD BG_BRIGHT_BLACK = 0 | 0x0080;
|
||||||
|
const WORD BG_BRIGHT_RED = BG_RED | 0x0080;
|
||||||
|
const WORD BG_BRIGHT_GREEN = BG_GREEN | 0x0080;
|
||||||
|
const WORD BG_BRIGHT_YELLOW = BG_YELLOW | 0x0080;
|
||||||
|
const WORD BG_BRIGHT_BLUE = BG_BLUE | 0x0080;
|
||||||
|
const WORD BG_BRIGHT_MAGENTA = BG_RED | BG_BLUE | 0x0080;
|
||||||
|
const WORD BG_BRIGHT_CYAN = BG_GREEN | BG_BLUE | 0x0080;
|
||||||
|
const WORD BG_BRIGHT_WHITE = BG_RED | BG_GREEN | BG_BLUE | 0x0080;
|
||||||
|
|
||||||
|
const WORD BG_DEFAULT = BG_WHITE;
|
||||||
|
}
|
36
main.cpp
36
main.cpp
@@ -1,5 +1,25 @@
|
|||||||
|
// Josh's Logger
|
||||||
|
// Minimal, robust, Modern (C++20) Logging Framework
|
||||||
|
// Created by Joshua O'Leary @ Redacted Software, June 2024
|
||||||
|
// Contact: josh@redacted.cc
|
||||||
|
// Contributors: william@redacted.cc maxi@redacted.cc
|
||||||
|
// This work is dedicated to the public domain.
|
||||||
|
|
||||||
#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
|
LOGLEVEL(jlog::severity::debug); // <- see jlog::severity for full list of log levels
|
||||||
@@ -11,22 +31,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 :(
|
||||||
|
@@ -1,363 +1,17 @@
|
|||||||
#include <source_location>
|
|
||||||
#include <jlog/ansi_escape_codes.hpp>
|
|
||||||
#include <jlog/jlog.hpp>
|
#include <jlog/jlog.hpp>
|
||||||
#include <string>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
namespace jlog {
|
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) {
|
void log(std::vector<token> tokens) {
|
||||||
for (token t : tokens) {
|
for (token t: tokens) {
|
||||||
if (t.delimiter != "") {
|
if (!t.delimiter.empty())
|
||||||
log_to_console(std::format("{}{}{}{}{} ", t.colorCode, t.delimiter[0], t.content, t.delimiter[1], ansi_escape_codes::RESET));
|
log_to_console(std::format("{}{}{}{}{} ", t.colorCode.ansi_code, 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]));
|
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));
|
else
|
||||||
|
log_to_console(std::format("{}{}{} ", t.colorCode.ansi_code, t.content, ansi_escape_codes::RESET)),
|
||||||
log_to_file(t.content + " ");
|
log_to_file(t.content + " ");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log_to_console("\n");
|
log_to_console("\n");
|
||||||
log_to_file("\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});
|
|
||||||
}
|
|
||||||
}
|
|
454
src/jlog/shared/jlog.cpp
Normal file
454
src/jlog/shared/jlog.cpp
Normal file
@@ -0,0 +1,454 @@
|
|||||||
|
#include <jlog/jlog.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> trace_format(
|
||||||
|
const std::string& func,
|
||||||
|
const std::string& file,
|
||||||
|
int line)
|
||||||
|
{
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
return {trace, filedata};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> info_format(const std::string& message)
|
||||||
|
{
|
||||||
|
return log_format("INFO", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> warning_format(const std::string& message)
|
||||||
|
{
|
||||||
|
return log_format("INFO", message, color_codes::FG_YELLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> error_format(const std::string& message)
|
||||||
|
{
|
||||||
|
return log_format("ERROR", message, color_codes::FG_RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> verbose_format(const std::string& message)
|
||||||
|
{
|
||||||
|
return log_format("VERBOSE", message, color_codes::FG_CYAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> debug_format(const std::string& message)
|
||||||
|
{
|
||||||
|
return log_format("DEBUG", message, color_codes::FG_GREEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> debug_detailed_format(
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& func,
|
||||||
|
const std::string& file,
|
||||||
|
int line)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
const std::string& file,
|
||||||
|
int line)
|
||||||
|
{
|
||||||
|
return log_detailed_format("INFO", message, func, file, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> warning_detailed_format(
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& func,
|
||||||
|
const std::string& file,
|
||||||
|
int line)
|
||||||
|
{
|
||||||
|
return log_detailed_format("WARNING", message, func, file, line, color_codes::FG_YELLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> error_detailed_format(
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& func,
|
||||||
|
const std::string& file,
|
||||||
|
int line)
|
||||||
|
{
|
||||||
|
return log_detailed_format("ERROR", message, func, file, line, color_codes::FG_RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> fatal_format(const std::string& message)
|
||||||
|
{
|
||||||
|
return log_format("FATAL", message, color_codes::FG_BRIGHT_RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> verbose_detailed_format(
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& func,
|
||||||
|
const std::string& file,
|
||||||
|
int line)
|
||||||
|
{
|
||||||
|
return log_detailed_format("VERBOSE", message, func, file, line, color_codes::FG_CYAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> fatal_detailed_format(
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& func,
|
||||||
|
const std::string& file,
|
||||||
|
int line)
|
||||||
|
{
|
||||||
|
return log_detailed_format("FATAL", message, func, file, line, color_codes::FG_BRIGHT_RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> log_format(
|
||||||
|
const std::string& severity_name,
|
||||||
|
const std::string& message,
|
||||||
|
const colorcode& severity_cc)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = severity_cc, .content = severity_name};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
return {severity, content};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<token> log_detailed_format(
|
||||||
|
const std::string& severity_name,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& func,
|
||||||
|
const std::string& file,
|
||||||
|
int line,
|
||||||
|
const colorcode& severity_cc)
|
||||||
|
{
|
||||||
|
std::vector<token> tokens;
|
||||||
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||||
|
auto tf_tokens = jlog::trace_format(func, file, line);
|
||||||
|
auto lf_tokens = jlog::log_format(severity_name, message, severity_cc);
|
||||||
|
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 info_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({timestamp, trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void sinfo_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void usinfo_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_WHITE, .content = "INFO"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
log({severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void verbose_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({timestamp, trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void sverbose_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void usverbose_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_CYAN, .content = "VERBOSE"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
log({severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void debug_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({timestamp, trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdebug_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void usdebug_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "DEBUG"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
log({severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void warning_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "WARNING"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({timestamp, trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void swarning_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "WARNING"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void uswarning_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "WARNING"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
log({severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_GREEN, .content = "ERROR"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({timestamp, trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void serror_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_RED, .content = "ERROR"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void userror_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_RED, .content = "ERROR"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
log({severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void fatal_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_RED, .content = "FATAL"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({timestamp, trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void sfatal_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto timestamp = token{.content = jlog::get_timestamp()};
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_BRIGHT_RED, .content = "FATAL"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
auto trace = token{.content = func};
|
||||||
|
auto filedata = token{.content = std::format("{}:{}", file, line)};
|
||||||
|
log({trace, filedata, severity, content});
|
||||||
|
}
|
||||||
|
|
||||||
|
void usfatal_spec(const std::string& message, const std::string& func, const std::string& file, int line)
|
||||||
|
{
|
||||||
|
auto severity = token{.colorCode = color_codes::FG_BRIGHT_RED, .content = "FATAL"};
|
||||||
|
auto content = token{.content = message, .delimiter = ""};
|
||||||
|
log({severity, content});
|
||||||
|
}
|
||||||
|
}
|
@@ -1,312 +1,26 @@
|
|||||||
#include <source_location>
|
|
||||||
#include <jlog/ansi_escape_codes.hpp>
|
|
||||||
#include <jlog/jlog.hpp>
|
#include <jlog/jlog.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
namespace jlog {
|
inline void SetConsoleTextColor(WORD color) {
|
||||||
std::string get_timestamp() {
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
|
||||||
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) {
|
namespace jlog
|
||||||
std::cout << message;
|
{
|
||||||
}
|
void log(const std::vector<token> tokens) {
|
||||||
|
|
||||||
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) {
|
for (const token& t : tokens) {
|
||||||
if (!t.delimiter.empty()) {
|
if (!t.delimiter.empty()) {
|
||||||
ansi_escape_codes::SetConsoleTextColor(t.colorCode);
|
SetConsoleTextColor(t.colorCode.nt_code);
|
||||||
log_to_console(std::string(1, t.delimiter[0]) + t.content + std::string(1, t.delimiter[1]) + " ");
|
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]) + " ");
|
log_to_file(std::string(1, t.delimiter[0]) + t.content + std::string(1, t.delimiter[1]) + " ");
|
||||||
} else {
|
} else {
|
||||||
ansi_escape_codes::SetConsoleTextColor(t.colorCode);
|
SetConsoleTextColor(t.colorCode.nt_code);
|
||||||
log_to_console(t.content + " ");
|
log_to_console(t.content + " ");
|
||||||
log_to_file(t.content + " ");
|
log_to_file(t.content + " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ansi_escape_codes::SetConsoleTextColor(ansi_escape_codes::FG_DEFAULT);
|
SetConsoleTextColor(color_codes::FG_DEFAULT.nt_code);
|
||||||
log_to_console("\n");
|
log_to_console("\n");
|
||||||
log_to_file("\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});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user