Skip to content

Commit

Permalink
#5231: Console is showing log output again
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 1, 2020
1 parent 26675d5 commit 1e32e19
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
8 changes: 3 additions & 5 deletions libs/wxutil/ConsoleView.cpp
@@ -1,6 +1,7 @@
#include "ConsoleView.h"

#include "imodule.h"
#include "iradiant.h"
#include "string/replace.h"

namespace wxutil
Expand Down Expand Up @@ -46,19 +47,16 @@ void ConsoleView::flushLine()
{
std::lock_guard<std::mutex> lock(_lineBufferMutex);

_lineBuffer.push_back(std::make_pair(_bufferMode, std::string()));
_lineBuffer.emplace_back(_bufferMode, std::string());
_lineBuffer.back().second.swap(_buffer);
}
}

void ConsoleView::onIdle()
{
#if 0 // TODO CoreModule
// Idle events occur in the main thread - prevent interrupting
// threads in the middle of a line
std::lock_guard<std::mutex> idleLock(
module::GlobalModuleRegistry().getApplicationContext().getStreamLock());
#endif
std::lock_guard<std::mutex> idleLock(GlobalRadiantCore().getLogWriter().getStreamLock());

flushLine();

Expand Down
1 change: 0 additions & 1 deletion radiant/RadiantApp.cpp
Expand Up @@ -5,7 +5,6 @@
#include "version.h"

#include "log/PIDFile.h"
#include "modulesystem/ModuleRegistry.h"
#include "module/CoreModule.h"
#include "modulesystem/StaticModule.h"

Expand Down
33 changes: 5 additions & 28 deletions radiant/log/Console.cpp
Expand Up @@ -8,7 +8,8 @@

#include <functional>

namespace ui {
namespace ui
{

Console::Console(wxWindow* parent) :
wxPanel(parent, wxID_ANY),
Expand All @@ -23,43 +24,19 @@ Console::Console(wxWindow* parent) :
GlobalCommandSystem().addCommand("clear",
std::bind(&Console::clearCmd, this, std::placeholders::_1));

#if 0 // TODO CoreModule
// Get a lock on the logging system before doing these changes
std::lock_guard<std::mutex> lock(module::GlobalModuleRegistry().getApplicationContext().getStreamLock());
std::lock_guard<std::mutex> lock(GlobalRadiantCore().getLogWriter().getStreamLock());

// We're ready to catch log output, register ourselves
applog::LogWriter::Instance().attach(this);
#endif

#if 0 // TODO CoreModule
// Copy the temporary buffers over
if (applog::StringLogDevice::InstancePtr() != NULL)
{
applog::StringLogDevice& logger = *applog::StringLogDevice::InstancePtr();

for (auto level : applog::AllLogLevels)
{
std::string bufferedText = logger.getString(static_cast<applog::LogLevel>(level));

if (bufferedText.empty()) continue;

writeLog(bufferedText + "\n", static_cast<applog::LogLevel>(level));
}
}

// Destruct the temporary buffer
applog::StringLogDevice::destroy();
#endif
GlobalRadiantCore().getLogWriter().attach(this);
}

Console::~Console()
{
// TODO - there might be more than one console instance handle this
GlobalCommandSystem().removeCommand("clear");

#if 0 // TODO CoreModule
applog::LogWriter::Instance().detach(this);
#endif
GlobalRadiantCore().getLogWriter().detach(this);
}

void Console::clearCmd(const cmd::ArgumentList& args)
Expand Down
25 changes: 25 additions & 0 deletions radiant/log/LogWriter.cpp
Expand Up @@ -2,6 +2,7 @@

#include <cassert>
#include <tuple>
#include "StringLogDevice.h"

namespace applog
{
Expand Down Expand Up @@ -39,7 +40,31 @@ std::mutex& LogWriter::getStreamLock()

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

_devices.insert(device);

if (firstDevice)
{
// The first device has the honour to receive all the buffered output
// Copy the temporary buffers over
if (applog::StringLogDevice::InstancePtr())
{
applog::StringLogDevice& logger = *applog::StringLogDevice::InstancePtr();

for (auto level : applog::AllLogLevels)
{
std::string bufferedText = logger.getString(static_cast<applog::LogLevel>(level));

if (bufferedText.empty()) continue;

device->writeLog(bufferedText + "\n", static_cast<applog::LogLevel>(level));
}
}

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

void LogWriter::detach(ILogDevice* device)
Expand Down

0 comments on commit 1e32e19

Please sign in to comment.