Skip to content

Commit 732bcf9

Browse files
authored
Log to stderr instead of stdout (#1285)
ConsoleAppender is writing logging output to stdout. In POSIX systems, logging should always go to stderr, and logging to stdout will cause problems for applications that have regular data output. Resolves: #1286 Signed-off-by: Christian Ocker <[email protected]>
1 parent e0ebd7b commit 732bcf9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

olp-cpp-sdk-core/src/logging/ConsoleAppender.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ IAppender& ConsoleAppender::append(const LogMessage& message) {
7575
#ifdef PORTING_PLATFORM_ANDROID
7676
android_append_in_chunks(message.level, message.tag, formattedMessage);
7777
#else
78-
std::cout << formattedMessage << std::endl;
78+
std::clog << formattedMessage << std::endl;
7979
#endif
8080
return *this;
8181
}

olp-cpp-sdk-core/tests/logging/LogTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ TEST(LogTest, DifferentLevelsForConsoleAndFileLogging) {
154154
}
155155
olp::logging::Log::setLevel(olp::logging::Level::Trace);
156156

157-
// redirecting cout to stringstream
157+
// redirecting clog to stringstream
158158
std::stringstream string_stream;
159-
auto default_cout_buffer = std::cout.rdbuf(string_stream.rdbuf());
159+
auto default_clog_buffer = std::clog.rdbuf(string_stream.rdbuf());
160160

161161
OLP_SDK_LOG_INFO("info", "Info "
162162
<< "message");
@@ -169,8 +169,8 @@ TEST(LogTest, DifferentLevelsForConsoleAndFileLogging) {
169169
OLP_SDK_LOG_FATAL("fatal", "Fatal "
170170
<< "message");
171171

172-
// resetting cout
173-
std::cout.rdbuf(default_cout_buffer);
172+
// resetting clog
173+
std::clog.rdbuf(default_clog_buffer);
174174

175175
// Clear out configuration so the file file handles are closed.
176176
olp::logging::Log::configure(olp::logging::Configuration::createDefault());

0 commit comments

Comments
 (0)