From 1e32e199997660c8b08048fe7c210d80842e4dc7 Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 1 May 2020 05:30:51 +0200 Subject: [PATCH] #5231: Console is showing log output again --- libs/wxutil/ConsoleView.cpp | 8 +++----- radiant/RadiantApp.cpp | 1 - radiant/log/Console.cpp | 33 +++++---------------------------- radiant/log/LogWriter.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/libs/wxutil/ConsoleView.cpp b/libs/wxutil/ConsoleView.cpp index f2b57182d1..d3d82a2deb 100644 --- a/libs/wxutil/ConsoleView.cpp +++ b/libs/wxutil/ConsoleView.cpp @@ -1,6 +1,7 @@ #include "ConsoleView.h" #include "imodule.h" +#include "iradiant.h" #include "string/replace.h" namespace wxutil @@ -46,19 +47,16 @@ void ConsoleView::flushLine() { std::lock_guard 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 idleLock( - module::GlobalModuleRegistry().getApplicationContext().getStreamLock()); -#endif + std::lock_guard idleLock(GlobalRadiantCore().getLogWriter().getStreamLock()); flushLine(); diff --git a/radiant/RadiantApp.cpp b/radiant/RadiantApp.cpp index 6d6e6416a0..d848ac1e22 100644 --- a/radiant/RadiantApp.cpp +++ b/radiant/RadiantApp.cpp @@ -5,7 +5,6 @@ #include "version.h" #include "log/PIDFile.h" -#include "modulesystem/ModuleRegistry.h" #include "module/CoreModule.h" #include "modulesystem/StaticModule.h" diff --git a/radiant/log/Console.cpp b/radiant/log/Console.cpp index d9845c948d..7d83f4fb83 100644 --- a/radiant/log/Console.cpp +++ b/radiant/log/Console.cpp @@ -8,7 +8,8 @@ #include -namespace ui { +namespace ui +{ Console::Console(wxWindow* parent) : wxPanel(parent, wxID_ANY), @@ -23,33 +24,11 @@ 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 lock(module::GlobalModuleRegistry().getApplicationContext().getStreamLock()); + std::lock_guard 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(level)); - - if (bufferedText.empty()) continue; - - writeLog(bufferedText + "\n", static_cast(level)); - } - } - - // Destruct the temporary buffer - applog::StringLogDevice::destroy(); -#endif + GlobalRadiantCore().getLogWriter().attach(this); } Console::~Console() @@ -57,9 +36,7 @@ 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) diff --git a/radiant/log/LogWriter.cpp b/radiant/log/LogWriter.cpp index 79f84b98e8..b314e795ec 100644 --- a/radiant/log/LogWriter.cpp +++ b/radiant/log/LogWriter.cpp @@ -2,6 +2,7 @@ #include #include +#include "StringLogDevice.h" namespace applog { @@ -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(level)); + + if (bufferedText.empty()) continue; + + device->writeLog(bufferedText + "\n", static_cast(level)); + } + } + + // Destruct the temporary buffer + applog::StringLogDevice::destroy(); + } } void LogWriter::detach(ILogDevice* device)