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.
This commit is contained in:
Tor Lillqvist 2018-09-18 15:27:17 +03:00 committed by Tor Lillqvist
parent c09dfda052
commit 763a27280a

View file

@ -13,6 +13,8 @@
#include <chrono>
#include <condition_variable>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <mutex>
#include <thread>
@ -80,7 +82,10 @@ static std::vector<FakeSocketPair>& 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 "";