From 1c5152808afda8a7e45e5d160454e13f60ca7958 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Wed, 2 Sep 2020 17:33:18 +1000 Subject: [PATCH 1/3] WARNING,ERROR,FATAL to CERR, add custom CUSTOM_CERR redirection --- src/easylogging++.cc | 8 +++++--- src/easylogging++.h | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/easylogging++.cc b/src/easylogging++.cc index 0d7dea0c9..b4ecd6be9 100644 --- a/src/easylogging++.cc +++ b/src/easylogging++.cc @@ -2240,7 +2240,8 @@ void DefaultLogDispatchCallback::dispatch(base::type::string_t&& logLine) { if (m_data->logMessage()->logger()->m_typedConfigurations->toStandardOutput(m_data->logMessage()->level())) { if (ELPP->hasFlag(LoggingFlag::ColoredTerminalOutput)) m_data->logMessage()->logger()->logBuilder()->convertToColoredOutput(&logLine, m_data->logMessage()->level()); - ELPP_COUT << ELPP_COUT_LINE(logLine); + if (m_data->logMessage()->level() == Level::Warning || m_data->logMessage()->level() == Level::Error || m_data->logMessage()->level() == Level::Fatal) ELPP_CERR << ELPP_COUT_LINE(logLine); + else ELPP_COUT << ELPP_COUT_LINE(logLine); } } #if defined(ELPP_SYSLOG) @@ -2281,10 +2282,11 @@ void AsyncLogDispatchCallback::handle(const LogDispatchData* data) { && data->logMessage()->logger()->typedConfigurations()->toStandardOutput(data->logMessage()->level())) { if (ELPP->hasFlag(LoggingFlag::ColoredTerminalOutput)) data->logMessage()->logger()->logBuilder()->convertToColoredOutput(&logLine, data->logMessage()->level()); - ELPP_COUT << ELPP_COUT_LINE(logLine); + if (data->logMessage()->level() == Level::Warning || data->logMessage()->level() == Level::Error || data->logMessage()->level() == Level::Fatal) ELPP_CERR << ELPP_COUT_LINE(logLine); + else ELPP_COUT << ELPP_COUT_LINE(logLine); } // Save resources and only queue if we want to write to file otherwise just ignore handler - if (data->logMessage()->logger()->typedConfigurations()->toFile(data->logMessage()->level())) { + if (data->logMessage()->logger()->typedConfigurations()->toFile(level)) { ELPP->asyncLogQueue()->push(AsyncLogItem(*(data->logMessage()), *data, logLine)); } } diff --git a/src/easylogging++.h b/src/easylogging++.h index 37e753fcd..8e7d281d3 100644 --- a/src/easylogging++.h +++ b/src/easylogging++.h @@ -503,6 +503,7 @@ namespace type { #undef ELPP_LITERAL #undef ELPP_STRLEN #undef ELPP_COUT +#undef ELPP_CERR #if defined(ELPP_UNICODE) # define ELPP_LITERAL(txt) L##txt # define ELPP_STRLEN wcslen @@ -511,6 +512,11 @@ namespace type { # else # define ELPP_COUT std::wcout # endif // defined ELPP_CUSTOM_COUT +# if defined ELPP_CUSTOM_CERR +# define ELPP_CERR ELPP_CUSTOM_CERR +# else +# define ELPP_CERR std::wcerr +# endif // defined ELPP_CUSTOM_CERR typedef wchar_t char_t; typedef std::wstring string_t; typedef std::wstringstream stringstream_t; @@ -524,6 +530,11 @@ typedef std::wostream ostream_t; # else # define ELPP_COUT std::cout # endif // defined ELPP_CUSTOM_COUT +# if defined ELPP_CUSTOM_CERR +# define ELPP_CERR ELPP_CUSTOM_CERR +# else +# define ELPP_CERR std::cerr +# endif // defined ELPP_CUSTOM_CERR typedef char char_t; typedef std::string string_t; typedef std::stringstream stringstream_t; From de19a319b78f8aa2a9b7a61820655768deb71cf4 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Wed, 2 Sep 2020 17:45:28 +1000 Subject: [PATCH 2/3] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 68b734af3..0f6af45c1 100644 --- a/README.md +++ b/README.md @@ -518,6 +518,7 @@ Some of logging options can be set by macros, this is a thoughtful decision, for | `ELPP_DISABLE_LOG_FILE_FROM_ARG` | Forcefully disables ability to set default log file from command-line arguments | | `ELPP_WINSOCK2` | On windows system force to use `winsock2.h` instead of `winsock.h` when `WIN32_LEAN_AND_MEAN` is defined | | `ELPP_CUSTOM_COUT` (advanced) | Resolves to a value e.g, `#define ELPP_CUSTOM_COUT qDebug()` or `#define ELPP_CUSTOM_COUT std::cerr`. This will use the value for standard output (instead of using `std::cout`| +| `ELPP_CUSTOM_CERR` (advanced) | Resolves to a value e.g, `#define ELPP_CUSTOM_CERR qDebug()` or `#define ELPP_CUSTOM_CERR std::cout`. This will use the value for standard output (instead of using `std::cerr`| | `ELPP_CUSTOM_COUT_LINE` (advanced) | Used with `ELPP_CUSTOM_COUT` to define how to write a log line with custom cout. e.g, `#define ELPP_CUSTOM_COUT_LINE(msg) QString::fromStdString(msg).trimmed()` | | `ELPP_NO_CHECK_MACROS` | Do not define the *CHECK* macros | | `ELPP_NO_DEBUG_MACROS` | Do not define the *DEBUG* macros | From 48099878a8e7be0e132bb76b78e885a4896ed51b Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Wed, 2 Sep 2020 17:52:51 +1000 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b53f9a3f8..855d8379c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## [9.96.8] - 02-09-2020 +- Adds support for easyloggingpp to log WARNING, ERROR, and FATAL to standard error. this befaviour can be reverted to old behaviour by defining `#define ELPP_CUSTOM_CERR std::cout`. this provides the the ability for CHECK macros and application abortion messages to be written to standard error instead of standard output. this is required in order for DEATH_TEST macro's in google test to match against easyloggingpp output, for example, `ASSERT_DEATH({CHECK_EQ(1, 2) << "error: value_a is not equal to value_b"; }, ".*value_a is not equal to value_b");` + ## [9.96.7] - 24-11-2018 - Adds support for compiling easyloggingpp using Emscripten. This allows the library to be compiled into Javascript or WebAssembly and run in the browser while logging to the browser's Javascript console.