Mercurial > hg > orthanc
diff UnitTestsSources/LoggingTests.cpp @ 4008:2d4427ca4be9
removed Core/LoggingUtils.h
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Jun 2020 08:47:43 +0200 |
parents | 9b5ace33a00d |
children | 27628b0f6ada |
line wrap: on
line diff
--- a/UnitTestsSources/LoggingTests.cpp Sat Jun 06 14:50:21 2020 +0200 +++ b/UnitTestsSources/LoggingTests.cpp Mon Jun 08 08:47:43 2020 +0200 @@ -41,7 +41,6 @@ #include <sstream> #include "../Core/Logging.h" -#include "../Core/LoggingUtils.h" using namespace Orthanc::Logging; @@ -64,19 +63,19 @@ } /** -Extracts the log line payload + Extracts the log line payload -"E0423 16:55:43.001194 LoggingTests.cpp:102] Foo bar?\n" ---> -"Foo bar" + "E0423 16:55:43.001194 LoggingTests.cpp:102] Foo bar?\n" + --> + "Foo bar" -If the log line cannot be matched, the function returns false. + If the log line cannot be matched, the function returns false. */ #define EOLSTRING "\n" static bool GetLogLinePayload(std::string& payload, - const std::string& logLine) + const std::string& logLine) { const char* regexStr = "[A-Z][0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6} " "[a-zA-Z\\.\\-_]+:[0-9]+\\] (.*)" EOLSTRING "$"; @@ -100,6 +99,7 @@ } } + namespace { class LoggingMementoScope @@ -114,8 +114,31 @@ Orthanc::Logging::Reset(); } }; + + + /** + * std::streambuf subclass used in FunctionCallingStream + **/ + template<typename T> + class FuncStreamBuf : public std::stringbuf + { + public: + FuncStreamBuf(T func) : func_(func) {} + + virtual int sync() + { + std::string text = this->str(); + const char* buf = text.c_str(); + func_(buf); + this->str(""); + return 0; + } + private: + T func_; + }; } + TEST(FuncStreamBuf, BasicTest) { LoggingMementoScope loggingConfiguration;