From 763a27280ad84fac1e26a9e0322408c1e7af8819 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Tue, 18 Sep 2018 15:27:17 +0300 Subject: [PATCH] Add possiblity to force logging to stderr with environment variable At least LOOLWSD.cpp has a couple of global variables of types that in their constructors invoke FakeSocket APIs. If we turn on FakeSocket logging (fakeSocketSetLoggingCallback()) only in the app's initialization code, we will miss logging from those global variable constructors. Sure, the clean solution would be to turn those global variables into members in the LOOLWSD class instead, but this will do for now. --- net/FakeSocket.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/FakeSocket.cpp b/net/FakeSocket.cpp index 9c83df4ce..99480dc4d 100644 --- a/net/FakeSocket.cpp +++ b/net/FakeSocket.cpp @@ -13,6 +13,8 @@ #include #include +#include +#include #include #include #include @@ -80,7 +82,10 @@ static std::vector& getFds() static std::string flush() { - if (loggingCallback != nullptr) + static bool alwaysStderr = std::getenv("FAKESOCKET_LOG_ALWAYS_STDERR") != nullptr; + if (alwaysStderr) + std::cerr << loggingBuffer.str() << std::endl; + else if (loggingCallback != nullptr) loggingCallback(loggingBuffer.str()); loggingBuffer.str(""); return "";