Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for easyloggingpp to log WARNING, ERROR, and FATAL to standard error #762

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [9.97.1] - 30-10-2022
- 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.97.0] - 25-12-2020
### Features
* Support for QNX OS
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,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 |
Expand Down
8 changes: 5 additions & 3 deletions src/easylogging++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,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)
Expand Down Expand Up @@ -2284,10 +2285,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));
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/easylogging++.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,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
Expand All @@ -516,6 +517,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;
Expand All @@ -529,6 +535,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;
Expand Down