From 3431752649c14e1b8a920247ee466cfc793eb664 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 3 Mar 2020 17:01:45 +0100 Subject: [PATCH 1/5] WIP --- .clang-tidy | 3 ++- slsSupportLib/include/logger.h | 26 ++++++++++++++++++-------- slsSupportLib/tests/CMakeLists.txt | 1 + slsSupportLib/tests/test-logger.cpp | 16 ++++++++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 slsSupportLib/tests/test-logger.cpp diff --git a/.clang-tidy b/.clang-tidy index eff429960..6e94d11e4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -17,7 +17,8 @@ Checks: '*, -google-runtime-references, -google-readability-todo, -google-readability-braces-around-statements, - -modernize-use-trailing-return-type' + -modernize-use-trailing-return-type, + -readability-isolate-declaration' HeaderFilterRegex: \.h AnalyzeTemporaryDtors: false diff --git a/slsSupportLib/include/logger.h b/slsSupportLib/include/logger.h index 5239cc0f2..c5e8933f3 100755 --- a/slsSupportLib/include/logger.h +++ b/slsSupportLib/include/logger.h @@ -5,7 +5,7 @@ #include #include #include - +#include #ifdef FIFODEBUG @@ -22,8 +22,8 @@ #endif -#define STRINGIFY(x) #x -#define TOSTRING(x) STRINGIFY(x) +// #define STRINGIFY(x) #x +// #define TOSTRING(x) STRINGIFY(x) #define MYCONCAT(x,y) #define __AT__ std::string(__FILE__) + std::string("::") + std::string(__func__) + std::string("(): ") #define __SHORT_FORM_OF_FILE__ \ @@ -162,13 +162,23 @@ inline FILE*& Output2FILE::Stream() return pStream; } +// inline void Output2FILE::Output(const std::string& msg) +// { +// FILE* pStream = Stream(); +// if (!pStream) +// return; +// fprintf(pStream, "%s", msg.c_str()); +// fflush(pStream); +// } + inline void Output2FILE::Output(const std::string& msg) { - FILE* pStream = Stream(); - if (!pStream) - return; - fprintf(pStream, "%s", msg.c_str()); - fflush(pStream); + std::cout << msg; + // FILE* pStream = Stream(); + // if (!pStream) + // return; + // fprintf(pStream, "%s", msg.c_str()); + // fflush(pStream); } inline void Output2FILE::Output(const std::string& msg, TLogLevel level) diff --git a/slsSupportLib/tests/CMakeLists.txt b/slsSupportLib/tests/CMakeLists.txt index bb84225d5..8832c3315 100755 --- a/slsSupportLib/tests/CMakeLists.txt +++ b/slsSupportLib/tests/CMakeLists.txt @@ -9,4 +9,5 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-ToString.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-TypeTraits.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-UdpRxSocket.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-logger.cpp ) \ No newline at end of file diff --git a/slsSupportLib/tests/test-logger.cpp b/slsSupportLib/tests/test-logger.cpp new file mode 100644 index 000000000..7d6439b6b --- /dev/null +++ b/slsSupportLib/tests/test-logger.cpp @@ -0,0 +1,16 @@ +#include "catch.hpp" +#include "logger.h" + +#include +#include +TEST_CASE("fail"){ + + FILE_LOG(logINFO) << "A message"; + + + + + // CHECK(false); + + +} \ No newline at end of file From ff9c37701bd0bd9de5a32ecfaa5e12e7c43acca4 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 4 Mar 2020 12:35:41 +0100 Subject: [PATCH 2/5] WIP --- slsSupportLib/include/logger.h | 26 +++------ slsSupportLib/include/logger2.h | 87 +++++++++++++++++++++++++++++ slsSupportLib/tests/test-logger.cpp | 43 ++++++++++++++ 3 files changed, 138 insertions(+), 18 deletions(-) create mode 100644 slsSupportLib/include/logger2.h diff --git a/slsSupportLib/include/logger.h b/slsSupportLib/include/logger.h index c5e8933f3..5239cc0f2 100755 --- a/slsSupportLib/include/logger.h +++ b/slsSupportLib/include/logger.h @@ -5,7 +5,7 @@ #include #include #include -#include + #ifdef FIFODEBUG @@ -22,8 +22,8 @@ #endif -// #define STRINGIFY(x) #x -// #define TOSTRING(x) STRINGIFY(x) +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) #define MYCONCAT(x,y) #define __AT__ std::string(__FILE__) + std::string("::") + std::string(__func__) + std::string("(): ") #define __SHORT_FORM_OF_FILE__ \ @@ -162,23 +162,13 @@ inline FILE*& Output2FILE::Stream() return pStream; } -// inline void Output2FILE::Output(const std::string& msg) -// { -// FILE* pStream = Stream(); -// if (!pStream) -// return; -// fprintf(pStream, "%s", msg.c_str()); -// fflush(pStream); -// } - inline void Output2FILE::Output(const std::string& msg) { - std::cout << msg; - // FILE* pStream = Stream(); - // if (!pStream) - // return; - // fprintf(pStream, "%s", msg.c_str()); - // fflush(pStream); + FILE* pStream = Stream(); + if (!pStream) + return; + fprintf(pStream, "%s", msg.c_str()); + fflush(pStream); } inline void Output2FILE::Output(const std::string& msg, TLogLevel level) diff --git a/slsSupportLib/include/logger2.h b/slsSupportLib/include/logger2.h new file mode 100644 index 000000000..239a7567e --- /dev/null +++ b/slsSupportLib/include/logger2.h @@ -0,0 +1,87 @@ +#pragma once +/*Utility to log to console*/ + +#include "ansi.h" //Colors +#include "logger.h" +#include +#include +#include +#include +#include + +/* +Define the max level that is visible +The compiler should optimize away any calls below +this level +*/ +#ifndef LOG_MAX_LEVEL +#define LOG_MAX_LEVEL logINFO +#endif + +namespace sls { +class Logger { + std::ostringstream os; + TLogLevel level = LOG_MAX_LEVEL; + + public: + Logger() = default; + Logger(TLogLevel level) : level(level){}; + ~Logger() { + // output happens in the destructor to allow for << + os << Reset() << '\n'; + std::clog << os.str(); // Single write + } + + static TLogLevel &ReportingLevel() { // singelton eeh + static TLogLevel reportingLevel = logINFO; + return reportingLevel; + } + + // Danger this buffer need as many elements as TLogLevel + static const char *Color(TLogLevel level) { + static const char *const colors[] = { + RED BOLD, YELLOW BOLD, RESET, BLUE, RED, RESET, + RESET, RESET, RESET, RESET, RESET, RESET}; + return colors[level]; + } + static const char *Reset() { + static const char *reset = RESET; + return reset; + } + + // Danger this buffer need as many elements as TLogLevel + static std::string ToString(TLogLevel level) { + static const char *const buffer[] = { + "ERROR", "WARNING", "INFO", "INFO", "INFO", "INFO", + "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4", "DEBUG5"}; + return buffer[level]; + } + + std::ostringstream &Get() { + os << Color(level); + os << "- " << Time(); + os << " " << ToString(level) << ": "; + return os; + } + std::string Time(decltype(std::chrono::system_clock::now()) now = + std::chrono::system_clock::now()) { + std::ostringstream oss; + auto ms = std::chrono::duration_cast( + now.time_since_epoch()) % + 1000; + std::time_t now_time = std::chrono::system_clock::to_time_t(now); + oss << std::put_time(std::localtime(&now_time), "%H:%M:%S") << "." + << std::setw(3) << std::setfill('0') << ms.count(); + return oss.str(); + } +}; + +#define LOG(level) \ + if (level > LOG_MAX_LEVEL) \ + ; \ + else if (level > sls::Logger::ReportingLevel()) \ + ; \ + else \ + sls::Logger(level).Get() + +} // namespace sls diff --git a/slsSupportLib/tests/test-logger.cpp b/slsSupportLib/tests/test-logger.cpp index 7d6439b6b..a150ae812 100644 --- a/slsSupportLib/tests/test-logger.cpp +++ b/slsSupportLib/tests/test-logger.cpp @@ -1,13 +1,56 @@ #include "catch.hpp" #include "logger.h" +#include "logger2.h" #include #include +#include + +TEST_CASE("Get time"){ + auto now = std::chrono::system_clock::now(); + sls::Logger log; + auto time = log.Time(now); + +} + TEST_CASE("fail"){ FILE_LOG(logINFO) << "A message"; + FILE_LOG(logWARNING) << "An error"; + FILE_LOG(logERROR) << "A warning"; + +// sls::Logger::ReportingLevel() = logERROR; + // std::cout << sls::Logger::ReportingLevel() << '\n'; + LOG(logINFO) << "A new message"; + LOG(logERROR) << "A new error"; + LOG(logWARNING) << "A new warning"; + + LOG(logDEBUG3) << "This should not be printed"; + + std::ostringstream local; + auto clog_buff = std::clog.rdbuf(); + std::clog.rdbuf(local.rdbuf()); + LOG(logERROR) << "This should also not be printed"; + + std::clog.rdbuf(clog_buff); // restore + LOG(logERROR) << "But this should"; + + std::cout << "we got: " << local.str() << '\n'; + // sls::Logger::ReportingLevel() = logDEBUG1; + // std::cout << sls::Logger::ReportingLevel() << '\n'; + // std::ostream& os = std::cout; + // Output2FILE::Stream(); + + // os << "hej pa dig\n"; + + // std::ostringstream oss; + // std::ostream& os = oss; + // auto& out = Output2FILE::Stream(); + // out = os; + // Output2FILE::Stream() = std::cout; + // FILE_LOG(logERROR) << "An error message"; // CHECK(false); From 661adaf4ed9ac6410f635a04a2cf5a3c307bce22 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 4 Mar 2020 15:25:49 +0100 Subject: [PATCH 3/5] WIP --- sample/CMakeLists.txt | 43 +++++++++-------- sample/using_logger.cpp | 32 +++++++++++++ slsSupportLib/include/logger2.h | 60 ++++++++++++------------ slsSupportLib/tests/test-logger.cpp | 71 ++++++++++++++--------------- 4 files changed, 118 insertions(+), 88 deletions(-) create mode 100644 sample/using_logger.cpp diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index a1d2e21c1..dca5fd59b 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -1,36 +1,35 @@ -add_executable(a api.cpp) -target_link_libraries(a - slsDetectorShared +add_executable(using_logger using_logger.cpp) +target_link_libraries(using_logger slsSupportLib pthread rt ) -set_target_properties(a PROPERTIES +set_target_properties(using_logger PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) -add_executable(result useResult.cpp) -target_link_libraries(result - slsDetectorShared -) +# add_executable(result useResult.cpp) +# target_link_libraries(result +# slsDetectorShared +# ) -set_target_properties(result PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin -) +# set_target_properties(result PROPERTIES +# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +# ) -add_executable(udp udp.cpp) -target_link_libraries(udp - slsDetectorShared - slsSupportLib - pthread - rt - fmt -) +# add_executable(udp udp.cpp) +# target_link_libraries(udp +# slsDetectorShared +# slsSupportLib +# pthread +# rt +# fmt +# ) -set_target_properties(udp PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin -) +# set_target_properties(udp PROPERTIES +# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +# ) diff --git a/sample/using_logger.cpp b/sample/using_logger.cpp new file mode 100644 index 000000000..394dbca0c --- /dev/null +++ b/sample/using_logger.cpp @@ -0,0 +1,32 @@ +#include "logger.h" +#include "logger2.h" + +#include +#include +int main(){ + + std::cout << "Compare output between old and new:\n"; + FILE_LOG(logINFO) << "Old message"; + LOG(logINFO) << "New message"; + FILE_LOG(logERROR) << "Old error"; + LOG(logERROR) << "New error"; + FILE_LOG(logWARNING) << "Old warning"; + LOG(logWARNING) << "New warning"; + + // // sls::Logger::ReportingLevel() = logERROR; + + // const auto N = 100000; + // auto t0 = std::chrono::steady_clock::now(); + // for (int i = 0; i!=N; ++i){ + // // LOG(logWARNING) << "HEY"; + // FILE_LOG(logWARNING) << "HEY"; + // } + // auto t1 = std::chrono::steady_clock::now(); + // for (int i = 0; i!=N; ++i){ + // LOG(logWARNING) << "HEY"; + // } + // auto t2 = std::chrono::steady_clock::now(); + + // std::cout << "Old: " << (t1-t0).count() << "\n"; + // std::cout << "New: " << (t2-t1).count() << "\n"; +} \ No newline at end of file diff --git a/slsSupportLib/include/logger2.h b/slsSupportLib/include/logger2.h index 239a7567e..4be5da88f 100644 --- a/slsSupportLib/include/logger2.h +++ b/slsSupportLib/include/logger2.h @@ -1,33 +1,26 @@ #pragma once /*Utility to log to console*/ -#include "ansi.h" //Colors -#include "logger.h" +#include "ansi.h" //Colors +#include "logger.h" //for enum, to be removed #include -#include #include -#include -#include -/* -Define the max level that is visible -The compiler should optimize away any calls below -this level -*/ -#ifndef LOG_MAX_LEVEL -#define LOG_MAX_LEVEL logINFO +// Compiler should optimize away anything below this value +#ifndef LOG_MAX_REPORTING_LEVEL +#define LOG_MAX_REPORTING_LEVEL logINFO #endif namespace sls { class Logger { std::ostringstream os; - TLogLevel level = LOG_MAX_LEVEL; + TLogLevel level = LOG_MAX_REPORTING_LEVEL; public: Logger() = default; Logger(TLogLevel level) : level(level){}; ~Logger() { - // output happens in the destructor to allow for << + // output in the destructor to allow for << syntax os << Reset() << '\n'; std::clog << os.str(); // Single write } @@ -38,13 +31,14 @@ class Logger { } // Danger this buffer need as many elements as TLogLevel - static const char *Color(TLogLevel level) { + static const char *Color(TLogLevel level) noexcept { static const char *const colors[] = { RED BOLD, YELLOW BOLD, RESET, BLUE, RED, RESET, RESET, RESET, RESET, RESET, RESET, RESET}; return colors[level]; } - static const char *Reset() { + + static const char *Reset() noexcept { static const char *reset = RESET; return reset; } @@ -58,26 +52,32 @@ class Logger { } std::ostringstream &Get() { - os << Color(level); - os << "- " << Time(); - os << " " << ToString(level) << ": "; + os << Color(level) << "- " << Timestamp() << " " << ToString(level) + << ": "; return os; } - std::string Time(decltype(std::chrono::system_clock::now()) now = - std::chrono::system_clock::now()) { - std::ostringstream oss; - auto ms = std::chrono::duration_cast( - now.time_since_epoch()) % - 1000; - std::time_t now_time = std::chrono::system_clock::to_time_t(now); - oss << std::put_time(std::localtime(&now_time), "%H:%M:%S") << "." - << std::setw(3) << std::setfill('0') << ms.count(); - return oss.str(); + + std::string Timestamp() { + constexpr size_t buffer_len = 12; + char buffer[buffer_len]; + time_t t; + time(&t); + tm r; + strftime(buffer, buffer_len, "%X", localtime_r(&t, &r)); + buffer[buffer_len - 1] = '\0'; + struct timeval tv; + gettimeofday(&tv, nullptr); + constexpr size_t result_len = 100; + char result[result_len]; + snprintf(result, result_len, "%s.%03ld", buffer, + (long)tv.tv_usec / 1000); + result[result_len - 1] = '\0'; + return result; } }; #define LOG(level) \ - if (level > LOG_MAX_LEVEL) \ + if (level > LOG_MAX_REPORTING_LEVEL) \ ; \ else if (level > sls::Logger::ReportingLevel()) \ ; \ diff --git a/slsSupportLib/tests/test-logger.cpp b/slsSupportLib/tests/test-logger.cpp index a150ae812..bcf371683 100644 --- a/slsSupportLib/tests/test-logger.cpp +++ b/slsSupportLib/tests/test-logger.cpp @@ -6,54 +6,53 @@ #include #include -TEST_CASE("Get time"){ - auto now = std::chrono::system_clock::now(); - sls::Logger log; - auto time = log.Time(now); +using sls::Logger; +TEST_CASE("LogLevel to string") { + CHECK(Logger::ToString(logERROR) == "ERROR"); + CHECK(Logger::ToString(logWARNING) == "WARNING"); + CHECK(Logger::ToString(logINFOBLUE) == "INFO"); + CHECK(Logger::ToString(logINFOGREEN) == "INFO"); + CHECK(Logger::ToString(logINFORED) == "INFO"); + CHECK(Logger::ToString(logINFO) == "INFO"); + CHECK(Logger::ToString(logDEBUG) == "DEBUG"); + CHECK(Logger::ToString(logDEBUG1) == "DEBUG1"); + CHECK(Logger::ToString(logDEBUG2) == "DEBUG2"); + CHECK(Logger::ToString(logDEBUG3) == "DEBUG3"); + CHECK(Logger::ToString(logDEBUG4) == "DEBUG4"); + CHECK(Logger::ToString(logDEBUG5) == "DEBUG5"); } -TEST_CASE("fail"){ +TEST_CASE("get reset string"){ + std::string reset(Logger::Reset()); + CHECK(reset == RESET); +} - FILE_LOG(logINFO) << "A message"; - FILE_LOG(logWARNING) << "An error"; - FILE_LOG(logERROR) << "A warning"; +TEST_CASE("Test output") { -// sls::Logger::ReportingLevel() = logERROR; - // std::cout << sls::Logger::ReportingLevel() << '\n'; - LOG(logINFO) << "A new message"; - LOG(logERROR) << "A new error"; - LOG(logWARNING) << "A new warning"; + auto old_value = Logger::ReportingLevel(); - LOG(logDEBUG3) << "This should not be printed"; + Logger::ReportingLevel() = logERROR; + //Redirect std::clog to local buffer std::ostringstream local; auto clog_buff = std::clog.rdbuf(); std::clog.rdbuf(local.rdbuf()); - LOG(logERROR) << "This should also not be printed"; + //Try printing something with too low level + LOG(logDEBUG) << "This should not be printed"; + CHECK(local.str().empty()); + + //Try printing something with a higher level + LOG(logERROR) << "This should be printed"; + CHECK(!local.str().empty()); std::clog.rdbuf(clog_buff); // restore - LOG(logERROR) << "But this should"; - - std::cout << "we got: " << local.str() << '\n'; - - - // sls::Logger::ReportingLevel() = logDEBUG1; - // std::cout << sls::Logger::ReportingLevel() << '\n'; - // std::ostream& os = std::cout; - // Output2FILE::Stream(); - - // os << "hej pa dig\n"; - - // std::ostringstream oss; - // std::ostream& os = oss; - // auto& out = Output2FILE::Stream(); - // out = os; - // Output2FILE::Stream() = std::cout; - // FILE_LOG(logERROR) << "An error message"; - - - // CHECK(false); + Logger::ReportingLevel() = old_value; //reset + //Check that the message is in the printed string + auto r = local.str(); + auto pos = r.find("This should be printed"); + CHECK(pos != std::string::npos); + } \ No newline at end of file From c6ddd19c0fd679d2145a9be9c2f39253622df784 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 4 Mar 2020 15:38:21 +0100 Subject: [PATCH 4/5] WIP --- sample/using_logger.cpp | 44 +++++++++++++++++++---------- slsSupportLib/include/logger2.h | 11 ++------ slsSupportLib/tests/test-logger.cpp | 5 ---- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/sample/using_logger.cpp b/sample/using_logger.cpp index 394dbca0c..658f93910 100644 --- a/sample/using_logger.cpp +++ b/sample/using_logger.cpp @@ -3,8 +3,9 @@ #include #include -int main(){ +int main() { + //compare old and new std::cout << "Compare output between old and new:\n"; FILE_LOG(logINFO) << "Old message"; LOG(logINFO) << "New message"; @@ -13,20 +14,33 @@ int main(){ FILE_LOG(logWARNING) << "Old warning"; LOG(logWARNING) << "New warning"; - // // sls::Logger::ReportingLevel() = logERROR; + //Logging level can be configure at runtime + std::cout << "\n\n"; + std::cout << "The default macro controlled level is: " + << sls::Logger::ToString(LOG_MAX_REPORTING_LEVEL) << '\n'; + + sls::Logger::ReportingLevel() = logERROR; + LOG(logINFO) << "Now this is not written"; + LOG(logWARNING) << "and also not this"; - // const auto N = 100000; - // auto t0 = std::chrono::steady_clock::now(); - // for (int i = 0; i!=N; ++i){ - // // LOG(logWARNING) << "HEY"; - // FILE_LOG(logWARNING) << "HEY"; - // } - // auto t1 = std::chrono::steady_clock::now(); - // for (int i = 0; i!=N; ++i){ - // LOG(logWARNING) << "HEY"; - // } - // auto t2 = std::chrono::steady_clock::now(); + sls::Logger::ReportingLevel() = logINFO; + LOG(logINFO) << "But now we can see it"; - // std::cout << "Old: " << (t1-t0).count() << "\n"; - // std::cout << "New: " << (t2-t1).count() << "\n"; + + //The output can be redirected to another buffer + std::ostringstream local; + auto clog_buff = std::clog.rdbuf(); + std::clog.rdbuf(local.rdbuf()); + + LOG(logINFOBLUE) << "A message"; + LOG(logWARNING) << "And another one"; + + std::clog.rdbuf(clog_buff); // restore + + std::cout << "local buf:\n" << local.str(); + + LOG(logINFO) << "After reset we should print directly"; + LOG(logINFOBLUE) << "some infoBLUE text"; + LOG(logINFOGREEN) << "some infoGREEN text"; + LOG(logINFORED) << "some infoRED text"; } \ No newline at end of file diff --git a/slsSupportLib/include/logger2.h b/slsSupportLib/include/logger2.h index 4be5da88f..adc3ebb28 100644 --- a/slsSupportLib/include/logger2.h +++ b/slsSupportLib/include/logger2.h @@ -18,10 +18,10 @@ class Logger { public: Logger() = default; - Logger(TLogLevel level) : level(level){}; + explicit Logger(TLogLevel level) : level(level){}; ~Logger() { // output in the destructor to allow for << syntax - os << Reset() << '\n'; + os << RESET << '\n'; std::clog << os.str(); // Single write } @@ -33,16 +33,11 @@ class Logger { // Danger this buffer need as many elements as TLogLevel static const char *Color(TLogLevel level) noexcept { static const char *const colors[] = { - RED BOLD, YELLOW BOLD, RESET, BLUE, RED, RESET, + RED BOLD, YELLOW BOLD, BLUE, GREEN, RED, RESET, RESET, RESET, RESET, RESET, RESET, RESET}; return colors[level]; } - static const char *Reset() noexcept { - static const char *reset = RESET; - return reset; - } - // Danger this buffer need as many elements as TLogLevel static std::string ToString(TLogLevel level) { static const char *const buffer[] = { diff --git a/slsSupportLib/tests/test-logger.cpp b/slsSupportLib/tests/test-logger.cpp index bcf371683..d57b79866 100644 --- a/slsSupportLib/tests/test-logger.cpp +++ b/slsSupportLib/tests/test-logger.cpp @@ -23,11 +23,6 @@ TEST_CASE("LogLevel to string") { CHECK(Logger::ToString(logDEBUG5) == "DEBUG5"); } -TEST_CASE("get reset string"){ - std::string reset(Logger::Reset()); - CHECK(reset == RESET); -} - TEST_CASE("Test output") { auto old_value = Logger::ReportingLevel(); From 0e171f291d29e87cb0fb1781946949332b8a2554 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 9 Mar 2020 13:57:50 +0100 Subject: [PATCH 5/5] added std::flush --- sample/using_logger.cpp | 1 + slsSupportLib/include/logger2.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sample/using_logger.cpp b/sample/using_logger.cpp index 658f93910..97574a642 100644 --- a/sample/using_logger.cpp +++ b/sample/using_logger.cpp @@ -43,4 +43,5 @@ int main() { LOG(logINFOBLUE) << "some infoBLUE text"; LOG(logINFOGREEN) << "some infoGREEN text"; LOG(logINFORED) << "some infoRED text"; + } \ No newline at end of file diff --git a/slsSupportLib/include/logger2.h b/slsSupportLib/include/logger2.h index adc3ebb28..cbd0d31a3 100644 --- a/slsSupportLib/include/logger2.h +++ b/slsSupportLib/include/logger2.h @@ -22,7 +22,7 @@ class Logger { ~Logger() { // output in the destructor to allow for << syntax os << RESET << '\n'; - std::clog << os.str(); // Single write + std::clog << os.str() << std::flush; // Single write } static TLogLevel &ReportingLevel() { // singelton eeh