prettier logger
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#ifndef LOG_HPP
|
||||
#define LOG_HPP
|
||||
|
||||
#define log _log // comment to disable logging
|
||||
#define log(level, fmt, ...) _log(level, std::source_location::current(), fmt, ##__VA_ARGS__) // comment to disable logging
|
||||
// #define LOG_FILE_LOCATION "linuxSmartie.log.gz"
|
||||
|
||||
#ifdef log
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <print>
|
||||
#include <source_location>
|
||||
#include <string_view>
|
||||
|
||||
#ifdef LOG_FILE_LOCATION
|
||||
@@ -16,13 +17,26 @@
|
||||
inline std::mutex fmtx; // file logging mutex
|
||||
#endif
|
||||
|
||||
// #define FUNC_NAME pFname(std::source_location::current().function_name())
|
||||
|
||||
inline std::mutex cmtx; // console logging mutex
|
||||
enum class LOG { INF, WRN, ERR, DBG, START };
|
||||
|
||||
inline std::string_view pFname(std::string_view full) {
|
||||
if (auto pos = full.find(' '); pos != std::string_view::npos)
|
||||
full.remove_prefix(pos + 1);
|
||||
|
||||
if (auto pos = full.rfind('('); pos != std::string_view::npos)
|
||||
full.remove_suffix(full.size() - pos);
|
||||
|
||||
return full;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void _log(LOG level, std::string_view tag, std::format_string<Args...> str, Args&&... args) {
|
||||
inline void _log(LOG level, const std::source_location& loc, std::format_string<Args...> str, Args&&... args) {
|
||||
constexpr std::string_view reset = "\033[0m";
|
||||
constexpr std::string_view pattern = "[{}{}{}] ";
|
||||
std::string_view tag = pFname(loc.function_name());
|
||||
std::string_view color = "";
|
||||
|
||||
switch (level) {
|
||||
|
||||
Reference in New Issue
Block a user