add prefix to LOG_LEVEL

v1
Brett 2023-04-08 12:44:31 -04:00
parent 89df343e4f
commit 5116981057
7 changed files with 43 additions and 30 deletions

View File

@ -7,6 +7,7 @@ option(BUILD_STD "Build the BLT standard utilities." ON)
option(BUILD_PROFILING "Build the BLT profiler extension" ON) option(BUILD_PROFILING "Build the BLT profiler extension" ON)
option(BUILD_NBT "Build the BLT NBT + eNBT extension" ON) option(BUILD_NBT "Build the BLT NBT + eNBT extension" ON)
option(BUILD_TESTS "Build the BLT test set" OFF) option(BUILD_TESTS "Build the BLT test set" OFF)
option(BLT_ENABLE_LOGGING "Enable blt::logging" ON)
if(${BUILD_STD} OR ${BUILD_PROFILING}) if(${BUILD_STD} OR ${BUILD_PROFILING})
file(GLOB_RECURSE STD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/std/*.cpp") file(GLOB_RECURSE STD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/std/*.cpp")
@ -36,6 +37,7 @@ else()
endif() endif()
include_directories(include/) include_directories(include/)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/config/)
message("Standard Files ${STD_FILES}") message("Standard Files ${STD_FILES}")
message("Profiler Files ${PROFILING_FILES}") message("Profiler Files ${PROFILING_FILES}")

View File

@ -1,2 +1,7 @@
#ifndef BLT_CONFIG_H
#define BLT_CONFIG_H
#cmakedefine ZLIB_FOUND #cmakedefine ZLIB_FOUND
#cmakedefine BLT_ENABLE_LOGGING
#endif // BLT_CONFIG_H

View File

@ -54,7 +54,7 @@ namespace blt::profiling {
profile getProfile(const std::string& profileName); profile getProfile(const std::string& profileName);
void printProfile( void printProfile(
const std::string& profileName, logging::LOG_LEVEL loggingLevel = logging::NONE, const std::string& profileName, logging::LOG_LEVEL loggingLevel = logging::BLT_NONE,
bool averageHistory = false bool averageHistory = false
); );
@ -106,7 +106,7 @@ namespace blt::profiling {
/** /**
* Prints the profile order from least time to most time. * Prints the profile order from least time to most time.
* @param profileName the profile to print * @param profileName the profile to print
* @param loggingLevel blt::logging::LOG_LEVEL to log with (default: NONE) * @param loggingLevel blt::logging::LOG_LEVEL to log with (default: BLT_NONE)
* @param averageHistory use the historical collection of interval rows in an average or just the latest? (default: false) * @param averageHistory use the historical collection of interval rows in an average or just the latest? (default: false)
*/ */
#define BLT_PRINT_PROFILE(profileName, ...) blt::profiling::printProfile(profileName, ##__VA_ARGS__) #define BLT_PRINT_PROFILE(profileName, ...) blt::profiling::printProfile(profileName, ##__VA_ARGS__)

View File

@ -9,11 +9,17 @@
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <blt/config.h>
namespace blt::logging { namespace blt::logging {
enum LOG_LEVEL { enum LOG_LEVEL {
TRACE = 0, DEBUG = 1, INFO = 2, WARN = 3, ERROR = 4, FATAL = 5, NONE = 6 // normal
BLT_TRACE = 0, BLT_DEBUG = 1, BLT_INFO = 2,
// errors
BLT_WARN = 3, BLT_ERROR = 4, BLT_FATAL = 5,
// default
BLT_NONE = 6
}; };
struct LOG_PROPERTIES { struct LOG_PROPERTIES {
@ -25,7 +31,7 @@ namespace blt::logging {
// print the whole path or just the file name? // print the whole path or just the file name?
bool m_logFullPath = false; bool m_logFullPath = false;
const char* m_directory = "./"; const char* m_directory = "./";
LOG_LEVEL minLevel = TRACE; LOG_LEVEL minLevel = BLT_TRACE;
explicit constexpr LOG_PROPERTIES(bool useColor, bool logToConsole, bool logToFile, const char* directory): explicit constexpr LOG_PROPERTIES(bool useColor, bool logToConsole, bool logToFile, const char* directory):
m_useColor(useColor), m_logToConsole(logToConsole), m_logToFile(logToFile), m_directory(directory) {} m_useColor(useColor), m_logToConsole(logToConsole), m_logToFile(logToFile), m_directory(directory) {}
@ -50,14 +56,14 @@ namespace blt::logging {
static void flush_all(); static void flush_all();
}; };
static logger std_out{NONE}; static logger std_out{BLT_NONE};
static logger trace{TRACE}; static logger trace{BLT_TRACE};
static logger debug{DEBUG}; static logger debug{BLT_DEBUG};
static logger info{INFO}; static logger info{BLT_INFO};
static logger warn{WARN}; static logger warn{BLT_WARN};
static logger error{ERROR}; static logger error{BLT_ERROR};
static logger fatal{FATAL}; static logger fatal{BLT_FATAL};
static inline logger& getLoggerFromLevel(LOG_LEVEL level) { static inline logger& getLoggerFromLevel(LOG_LEVEL level) {
static logger loggerLevelDecode[7]{trace, debug, info, warn, error, fatal, std_out}; static logger loggerLevelDecode[7]{trace, debug, info, warn, error, fatal, std_out};
@ -111,12 +117,12 @@ namespace blt::logging {
#define BLT_ERROR(format, ...) #define BLT_ERROR(format, ...)
#define BLT_FATAL(format, ...) #define BLT_FATAL(format, ...)
#else #else
#define BLT_TRACE(format, ...) log_internal(format, blt::logging::TRACE, __FILE__, __LINE__, true, ##__VA_ARGS__) #define BLT_TRACE(format, ...) log_internal(format, blt::logging::BLT_TRACE, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define BLT_DEBUG(format, ...) log_internal(format, blt::logging::DEBUG, __FILE__, __LINE__, true, ##__VA_ARGS__) #define BLT_DEBUG(format, ...) log_internal(format, blt::logging::BLT_DEBUG, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define BLT_INFO(format, ...) log_internal(format, blt::logging::INFO, __FILE__, __LINE__, true, ##__VA_ARGS__) #define BLT_INFO(format, ...) log_internal(format, blt::logging::BLT_INFO, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define BLT_WARN(format, ...) log_internal(format, blt::logging::WARN, __FILE__, __LINE__, true, ##__VA_ARGS__) #define BLT_WARN(format, ...) log_internal(format, blt::logging::BLT_WARN, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define BLT_ERROR(format, ...) log_internal(format, blt::logging::ERROR, __FILE__, __LINE__, true, ##__VA_ARGS__) #define BLT_ERROR(format, ...) log_internal(format, blt::logging::BLT_ERROR, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define BLT_FATAL(format, ...) log_internal(format, blt::logging::FATAL, __FILE__, __LINE__, true, ##__VA_ARGS__) #define BLT_FATAL(format, ...) log_internal(format, blt::logging::BLT_FATAL, __FILE__, __LINE__, true, ##__VA_ARGS__)
#endif #endif
#endif //BLT_LOGGING_H #endif //BLT_LOGGING_H

View File

@ -88,12 +88,12 @@ namespace blt::logging {
}; };
const char* levelNames[6] = { const char* levelNames[6] = {
"[TRACE]: ", "[BLT_TRACE]: ",
"[DEBUG]: ", "[BLT_DEBUG]: ",
"[INFO]: ", "[BLT_INFO]: ",
"[WARN]: ", "[BLT_WARN]: ",
"[ERROR]: ", "[BLT_ERROR]: ",
"[FATAL]: ", "[BLT_FATAL]: ",
}; };
// by default everything is enabled // by default everything is enabled
@ -149,7 +149,7 @@ namespace blt::logging {
} }
if (BLT_LOGGING_PROPERTIES.m_logToConsole) { if (BLT_LOGGING_PROPERTIES.m_logToConsole) {
if (level > WARN) if (level > BLT_WARN)
std::cerr << outputString; std::cerr << outputString;
else else
std::cout << outputString; std::cout << outputString;
@ -188,7 +188,7 @@ namespace blt::logging {
if (blt::string::contains(str, "\n")){ if (blt::string::contains(str, "\n")){
// make sure new lines are properly formatted to prevent danging lines. Ie "[trace]: .... [debug]: ...." // make sure new lines are properly formatted to prevent danging lines. Ie "[trace]: .... [debug]: ...."
bool hasEndingLinefeed = str[str.length()-1] == '\n'; bool hasEndingLinefeed = str[str.length()-1] == '\n';
if (level == NONE) { if (level == BLT_NONE) {
std::cout << th_str; std::cout << th_str;
} else } else
logging::log(th_str, false, level, "", -1, !hasEndingLinefeed); logging::log(th_str, false, level, "", -1, !hasEndingLinefeed);

View File

@ -38,7 +38,7 @@ static void runProfilingAndTableTests() {
BLT_END_INTERVAL("Help", "UnderSet" + std::to_string(i)); BLT_END_INTERVAL("Help", "UnderSet" + std::to_string(i));
} }
BLT_PRINT_PROFILE("Help", blt::logging::LOG_LEVEL::TRACE); BLT_PRINT_PROFILE("Help", blt::logging::LOG_LEVEL::BLT_TRACE);
BLT_TRACE(""); BLT_TRACE("");
blt::string::TableFormatter formatter; blt::string::TableFormatter formatter;

View File

@ -140,9 +140,9 @@ static inline void test_queues() {
fill_queues(); fill_queues();
random_access(); random_access();
BLT_PRINT_PROFILE("Insert", blt::logging::LOG_LEVEL::INFO, true); BLT_PRINT_PROFILE("Insert", blt::logging::LOG_LEVEL::BLT_INFO, true);
BLT_PRINT_PROFILE("Access", blt::logging::LOG_LEVEL::INFO, true); BLT_PRINT_PROFILE("Access", blt::logging::LOG_LEVEL::BLT_INFO, true);
BLT_PRINT_PROFILE("Random", blt::logging::LOG_LEVEL::INFO, true); BLT_PRINT_PROFILE("Random", blt::logging::LOG_LEVEL::BLT_INFO, true);
} }
#endif //BLT_TESTS_QUEUE_TESTS_H #endif //BLT_TESTS_QUEUE_TESTS_H