Skip to content

Commit

Permalink
#5231: Console window (again) shows output from before it was attache…
Browse files Browse the repository at this point in the history
…d to the LogWriter
  • Loading branch information
codereader committed May 1, 2020
1 parent 31dca86 commit bec0e54
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
11 changes: 11 additions & 0 deletions include/ilogwriter.h
Expand Up @@ -37,6 +37,17 @@ class ILogDevice
* a log string as argument.
*/
virtual void writeLog(const std::string& outputStr, LogLevel level) = 0;

/**
* If this device is a console, it will be filled with the log output
* that has been collected before it has been attached.
* This is supposed to make it easier to inspect the startup phase opening
* the console viewer in the UI.
*/
virtual bool isConsole() const
{
return false;
}
};

/**
Expand Down
5 changes: 5 additions & 0 deletions radiant/log/Console.h
Expand Up @@ -56,6 +56,11 @@ class Console :
* (Note: this gets called by the LogWriter automatically).
*/
void writeLog(const std::string& outputStr, applog::LogLevel level) override;

bool isConsole() const override
{
return true; // Receive the buffered log output when attached
}
};

} // namespace ui
8 changes: 2 additions & 6 deletions radiant/log/LogWriter.cpp
Expand Up @@ -40,14 +40,11 @@ std::mutex& LogWriter::getStreamLock()

void LogWriter::attach(ILogDevice* device)
{
bool firstDevice = _devices.empty();

_devices.insert(device);

if (firstDevice)
if (device->isConsole())
{
// The first device has the honour to receive all the buffered output
// Copy the temporary buffers over
// The first console device receives all the buffered output
if (applog::StringLogDevice::InstancePtr())
{
applog::StringLogDevice& logger = *applog::StringLogDevice::InstancePtr();
Expand All @@ -62,7 +59,6 @@ void LogWriter::attach(ILogDevice* device)
}
}

// Destruct the temporary buffer
applog::StringLogDevice::destroy();
}
}
Expand Down

0 comments on commit bec0e54

Please sign in to comment.