add prefix to LOG_LEVEL
parent
89df343e4f
commit
5116981057
|
@ -7,6 +7,7 @@ option(BUILD_STD "Build the BLT standard utilities." ON)
|
|||
option(BUILD_PROFILING "Build the BLT profiler extension" ON)
|
||||
option(BUILD_NBT "Build the BLT NBT + eNBT extension" ON)
|
||||
option(BUILD_TESTS "Build the BLT test set" OFF)
|
||||
option(BLT_ENABLE_LOGGING "Enable blt::logging" ON)
|
||||
|
||||
if(${BUILD_STD} OR ${BUILD_PROFILING})
|
||||
file(GLOB_RECURSE STD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/std/*.cpp")
|
||||
|
@ -36,6 +37,7 @@ else()
|
|||
endif()
|
||||
|
||||
include_directories(include/)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/config/)
|
||||
|
||||
message("Standard Files ${STD_FILES}")
|
||||
message("Profiler Files ${PROFILING_FILES}")
|
||||
|
|
|
@ -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
|
|
@ -54,7 +54,7 @@ namespace blt::profiling {
|
|||
profile getProfile(const std::string& profileName);
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
|
@ -106,7 +106,7 @@ namespace blt::profiling {
|
|||
/**
|
||||
* Prints the profile order from least time to most time.
|
||||
* @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)
|
||||
*/
|
||||
#define BLT_PRINT_PROFILE(profileName, ...) blt::profiling::printProfile(profileName, ##__VA_ARGS__)
|
||||
|
|
|
@ -9,11 +9,17 @@
|
|||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <blt/config.h>
|
||||
|
||||
namespace blt::logging {
|
||||
|
||||
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 {
|
||||
|
@ -25,7 +31,7 @@ namespace blt::logging {
|
|||
// print the whole path or just the file name?
|
||||
bool m_logFullPath = false;
|
||||
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):
|
||||
m_useColor(useColor), m_logToConsole(logToConsole), m_logToFile(logToFile), m_directory(directory) {}
|
||||
|
@ -50,14 +56,14 @@ namespace blt::logging {
|
|||
static void flush_all();
|
||||
};
|
||||
|
||||
static logger std_out{NONE};
|
||||
static logger std_out{BLT_NONE};
|
||||
|
||||
static logger trace{TRACE};
|
||||
static logger debug{DEBUG};
|
||||
static logger info{INFO};
|
||||
static logger warn{WARN};
|
||||
static logger error{ERROR};
|
||||
static logger fatal{FATAL};
|
||||
static logger trace{BLT_TRACE};
|
||||
static logger debug{BLT_DEBUG};
|
||||
static logger info{BLT_INFO};
|
||||
static logger warn{BLT_WARN};
|
||||
static logger error{BLT_ERROR};
|
||||
static logger fatal{BLT_FATAL};
|
||||
|
||||
static inline logger& getLoggerFromLevel(LOG_LEVEL level) {
|
||||
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_FATAL(format, ...)
|
||||
#else
|
||||
#define BLT_TRACE(format, ...) log_internal(format, blt::logging::TRACE, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_DEBUG(format, ...) log_internal(format, blt::logging::DEBUG, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_INFO(format, ...) log_internal(format, blt::logging::INFO, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_WARN(format, ...) log_internal(format, blt::logging::WARN, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_ERROR(format, ...) log_internal(format, blt::logging::ERROR, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_FATAL(format, ...) log_internal(format, blt::logging::FATAL, __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::BLT_DEBUG, __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::BLT_WARN, __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::BLT_FATAL, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#endif //BLT_LOGGING_H
|
||||
|
|
|
@ -88,12 +88,12 @@ namespace blt::logging {
|
|||
};
|
||||
|
||||
const char* levelNames[6] = {
|
||||
"[TRACE]: ",
|
||||
"[DEBUG]: ",
|
||||
"[INFO]: ",
|
||||
"[WARN]: ",
|
||||
"[ERROR]: ",
|
||||
"[FATAL]: ",
|
||||
"[BLT_TRACE]: ",
|
||||
"[BLT_DEBUG]: ",
|
||||
"[BLT_INFO]: ",
|
||||
"[BLT_WARN]: ",
|
||||
"[BLT_ERROR]: ",
|
||||
"[BLT_FATAL]: ",
|
||||
};
|
||||
|
||||
// by default everything is enabled
|
||||
|
@ -149,7 +149,7 @@ namespace blt::logging {
|
|||
}
|
||||
|
||||
if (BLT_LOGGING_PROPERTIES.m_logToConsole) {
|
||||
if (level > WARN)
|
||||
if (level > BLT_WARN)
|
||||
std::cerr << outputString;
|
||||
else
|
||||
std::cout << outputString;
|
||||
|
@ -188,7 +188,7 @@ namespace blt::logging {
|
|||
if (blt::string::contains(str, "\n")){
|
||||
// make sure new lines are properly formatted to prevent danging lines. Ie "[trace]: .... [debug]: ...."
|
||||
bool hasEndingLinefeed = str[str.length()-1] == '\n';
|
||||
if (level == NONE) {
|
||||
if (level == BLT_NONE) {
|
||||
std::cout << th_str;
|
||||
} else
|
||||
logging::log(th_str, false, level, "", -1, !hasEndingLinefeed);
|
||||
|
|
|
@ -38,7 +38,7 @@ static void runProfilingAndTableTests() {
|
|||
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::string::TableFormatter formatter;
|
||||
|
|
|
@ -140,9 +140,9 @@ static inline void test_queues() {
|
|||
fill_queues();
|
||||
random_access();
|
||||
|
||||
BLT_PRINT_PROFILE("Insert", blt::logging::LOG_LEVEL::INFO, true);
|
||||
BLT_PRINT_PROFILE("Access", blt::logging::LOG_LEVEL::INFO, true);
|
||||
BLT_PRINT_PROFILE("Random", 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::BLT_INFO, true);
|
||||
BLT_PRINT_PROFILE("Random", blt::logging::LOG_LEVEL::BLT_INFO, true);
|
||||
}
|
||||
|
||||
#endif //BLT_TESTS_QUEUE_TESTS_H
|
||||
|
|
Loading…
Reference in New Issue