From bb270f5776171a29ded94d4cfff481bc7c98d321 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Sun, 7 Apr 2024 00:08:31 +0200 Subject: [PATCH] Fix SIOF (Static initializer order Fiasco) with lazy initialization of loggers: `clStandardPaths::Get().GetUserDataDir()` (called from Logger constructor) requires that Application is set. --- CodeLite/LSP/basic_types.cpp | 5 +- CodeLite/clModuleLogger.hpp | 24 +++--- CodeLite/ssh/clSSHChannel.cpp | 6 +- CodeLite/ssh/clSSHChannelCommon.cpp | 8 +- CodeLite/ssh/clSSHInteractiveChannel.cpp | 78 +++++++++---------- Plugin/LSP/LSPNetworkRemoteSTDIO.cpp | 14 ++-- Plugin/clRemoteHost.cpp | 22 +++--- Plugin/cl_remote_executor.cpp | 10 +-- .../wxTerminalAnsiEscapeHandler.cpp | 2 +- .../wxTerminalAnsiRendererInterface.cpp | 30 +++---- Plugin/wxTerminalCtrl/wxTerminalCtrl.cpp | 12 +-- .../wxTerminalCtrl/wxTerminalOutputCtrl.cpp | 5 +- 12 files changed, 109 insertions(+), 107 deletions(-) diff --git a/CodeLite/LSP/basic_types.cpp b/CodeLite/LSP/basic_types.cpp index 94cd6d1afc..4bddc09d56 100644 --- a/CodeLite/LSP/basic_types.cpp +++ b/CodeLite/LSP/basic_types.cpp @@ -13,7 +13,10 @@ INITIALISE_MODULE_LOG(LSP_LOG_HANDLER, "LSP", "lsp.log"); namespace LSP { -clModuleLogger& GetLogHandle() { return LSP_LOG_HANDLER; } +clModuleLogger& GetLogHandle() +{ + return LSP_LOG_HANDLER(); +} wxString FileNameToURI(const wxString& filename) { diff --git a/CodeLite/clModuleLogger.hpp b/CodeLite/clModuleLogger.hpp index 2744528793..dc2521314a 100644 --- a/CodeLite/clModuleLogger.hpp +++ b/CodeLite/clModuleLogger.hpp @@ -22,6 +22,9 @@ class WXDLLIMPEXP_CL clModuleLogger clModuleLogger(); ~clModuleLogger(); + clModuleLogger(clModuleLogger&&) = default; + clModuleLogger& operator=(clModuleLogger&&) = default; + /// Set the module name void SetModule(const wxString& name) { m_module = name; } @@ -249,20 +252,19 @@ template clModuleLogger& operator<<(clModuleLogger& logger, const T #define INITIALISE_MODULE_LOG(LOG, MODULE_NAME, FILE_NAME) \ namespace \ { \ - thread_local clModuleLogger LOG; \ - struct Init { \ - Init() \ - { \ + clModuleLogger& LOG() \ + { \ + thread_local static clModuleLogger instance = []() { \ wxFileName logfile{ clStandardPaths::Get().GetUserDataDir(), FILE_NAME }; \ logfile.AppendDir("logs"); \ logfile.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); \ - LOG.SetModule(MODULE_NAME); \ - LOG.Open(logfile.GetFullPath()); \ - } \ - }; \ - \ - /*Initialise our logger (once per thread)*/ \ - thread_local Init init; \ + clModuleLogger logger; \ + logger.SetModule(MODULE_NAME); \ + logger.Open(logfile.GetFullPath()); \ + return logger; \ + }(); \ + return instance; \ + } \ } #endif // CLMODULELOGGER_HPP diff --git a/CodeLite/ssh/clSSHChannel.cpp b/CodeLite/ssh/clSSHChannel.cpp index f71a61fa51..fa5098475f 100644 --- a/CodeLite/ssh/clSSHChannel.cpp +++ b/CodeLite/ssh/clSSHChannel.cpp @@ -125,7 +125,7 @@ void clSSHChannel::Close() if(m_hadErrors) { // log this - LOG_DEBUG(LOG) << "ssh session had errors. discarding it" << endl; + LOG_DEBUG(LOG()) << "ssh session had errors. discarding it" << endl; } else { // put back the ssh session @@ -140,7 +140,7 @@ IProcess::Ptr_t clSSHChannel::CreateAndExecuteScript(clSSH::Ptr_t ssh, clSSHDele bool wantStderr) { if(!ssh::write_remote_file_content(ssh, script_path, content)) { - LOG_ERROR(LOG) << "failed to write remote file:" << script_path << endl; + LOG_ERROR(LOG()) << "failed to write remote file:" << script_path << endl; return nullptr; } return Execute(ssh, std::move(deleter_cb), owner, script_path, wantStderr); @@ -154,7 +154,7 @@ IProcess::Ptr_t clSSHChannel::Execute(clSSH::Ptr_t ssh, clSSHDeleterFunc deleter channel = new clSSHChannel(ssh, std::move(deleter_cb), owner, wantStderr); channel->Open(); } catch(clException& e) { - LOG_ERROR(LOG) << "failed to open channel." << e.What() << endl; + LOG_ERROR(LOG()) << "failed to open channel." << e.What() << endl; wxDELETE(channel); return nullptr; } diff --git a/CodeLite/ssh/clSSHChannelCommon.cpp b/CodeLite/ssh/clSSHChannelCommon.cpp index b0459d390e..4746c3f5cf 100644 --- a/CodeLite/ssh/clSSHChannelCommon.cpp +++ b/CodeLite/ssh/clSSHChannelCommon.cpp @@ -37,14 +37,14 @@ void channel_read_internal(SSHChannel_t channel, ReadResult* result, bool isStde int bytes = ssh_channel_read_timeout(channel, buffer, sizeof(buffer) - 1, isStderr ? 1 : 0, 1); if(bytes == SSH_ERROR) { // an error - LOG_DEBUG(LOG) << "channel read error" << endl; + LOG_DEBUG(LOG()) << "channel read error" << endl; int exit_code = ssh_channel_get_exit_status(channel); result->exit_code = exit_code; result->rc = ssh::read_result::SSH_IO_ERROR; } else if(bytes == SSH_EOF) { // channel closed - LOG_DEBUG(LOG) << "channel read eof" << endl; + LOG_DEBUG(LOG()) << "channel read eof" << endl; int exit_code = ssh_channel_get_exit_status(channel); result->exit_code = exit_code; result->rc = ssh::read_result::SSH_CONN_CLOSED; @@ -52,7 +52,7 @@ void channel_read_internal(SSHChannel_t channel, ReadResult* result, bool isStde } else if(bytes == 0) { // timeout if(ssh_channel_is_eof(channel)) { - LOG_DEBUG(LOG) << "channel eof detected" << endl; + LOG_DEBUG(LOG()) << "channel eof detected" << endl; int exit_code = ssh_channel_get_exit_status(channel); result->exit_code = exit_code; result->rc = ssh::read_result::SSH_CONN_CLOSED; @@ -63,7 +63,7 @@ void channel_read_internal(SSHChannel_t channel, ReadResult* result, bool isStde result->rc = ssh::read_result::SSH_TIMEOUT; } } else { - LOG_DEBUG(LOG) << "read" << bytes << "bytes" << endl; + LOG_DEBUG(LOG()) << "read" << bytes << "bytes" << endl; buffer[bytes] = 0; result->exit_code = 0; result->rc = ssh::read_result::SSH_SUCCESS; diff --git a/CodeLite/ssh/clSSHInteractiveChannel.cpp b/CodeLite/ssh/clSSHInteractiveChannel.cpp index 99bcc28d5b..e9792cffb2 100644 --- a/CodeLite/ssh/clSSHInteractiveChannel.cpp +++ b/CodeLite/ssh/clSSHInteractiveChannel.cpp @@ -18,16 +18,16 @@ INITIALISE_SSH_LOG(LOG, "Interactive-Channel"); -#define CHECK_ARG(arg, msg) \ - if(!(arg)) { \ - LOG_WARNING(LOG) << msg << endl; \ - return nullptr; \ +#define CHECK_ARG(arg, msg) \ + if(!(arg)) { \ + LOG_WARNING(LOG()) << msg << endl; \ + return nullptr; \ } -#define CHECK_ARG_VOID(arg, msg) \ - if(!(arg)) { \ - LOG_WARNING(LOG) << msg << endl; \ - return; \ +#define CHECK_ARG_VOID(arg, msg) \ + if(!(arg)) { \ + LOG_WARNING(LOG()) << msg << endl; \ + return; \ } namespace @@ -46,12 +46,12 @@ struct CmdSignal { std::thread* start_helper_thread(SSHChannel_t channel, wxEvtHandler* handler, wxMessageQueue& Q) { - LOG_DEBUG(LOG) << "start_helper_thread is called" << endl; + LOG_DEBUG(LOG()) << "start_helper_thread is called" << endl; // our helper thread // 1) poll the channel for incoming data // 2) poll the `Q` for data to write to the remote process std::thread* thr = new std::thread([channel, &Q, handler]() mutable { - LOG_DEBUG(LOG) << "helper thread started" << endl; + LOG_DEBUG(LOG()) << "helper thread started" << endl; while(true) { // Poll the channel for output auto stdout_res = ssh::channel_read(channel, handler, false, true); @@ -79,11 +79,11 @@ std::thread* start_helper_thread(SSHChannel_t channel, wxEvtHandler* handler, wx // fall: timeout wxAny msg; if(Q.ReceiveTimeout(1, msg) == wxMSGQUEUE_NO_ERROR) { - LOG_DEBUG(LOG) << "got request from the queue" << endl; + LOG_DEBUG(LOG()) << "got request from the queue" << endl; // got a message if(msg.CheckType()) { // shutdown, terminate the channel - LOG_DEBUG(LOG) << "shutting down" << endl; + LOG_DEBUG(LOG()) << "shutting down" << endl; break; } else if(msg.CheckType()) { @@ -92,15 +92,15 @@ std::thread* start_helper_thread(SSHChannel_t channel, wxEvtHandler* handler, wx CmdWrite write_command; msg.GetAs(&write_command); - LOG_DEBUG(LOG) << "writing:" << write_command.content << endl; + LOG_DEBUG(LOG()) << "writing:" << write_command.content << endl; int rc = ssh_channel_write(channel, write_command.content.c_str(), write_command.content.size()); if(rc != write_command.content.size()) { - LOG_WARNING(LOG) << "failed to write:" << write_command.content << "to ssh channel" << endl; + LOG_WARNING(LOG()) << "failed to write:" << write_command.content << "to ssh channel" << endl; clCommandEvent event(wxEVT_SSH_CHANNEL_WRITE_ERROR); handler->QueueEvent(event.Clone()); break; } else { - LOG_DEBUG(LOG) << "successfully written:" << write_command.content << "to ssh channel" << endl; + LOG_DEBUG(LOG()) << "successfully written:" << write_command.content << "to ssh channel" << endl; } } else if(msg.CheckType()) { @@ -109,23 +109,23 @@ std::thread* start_helper_thread(SSHChannel_t channel, wxEvtHandler* handler, wx CmdSignal cmd; msg.GetAs(&cmd); - LOG_DEBUG(LOG) << "sending signal:" << cmd.signal_prefix << endl; + LOG_DEBUG(LOG()) << "sending signal:" << cmd.signal_prefix << endl; int rc = ssh_channel_request_send_signal(channel, cmd.signal_prefix.c_str()); if(rc != SSH_OK) { - LOG_WARNING(LOG) << "failed to send signal:" << cmd.signal_prefix << "to ssh channel" << endl; + LOG_WARNING(LOG()) << "failed to send signal:" << cmd.signal_prefix << "to ssh channel" << endl; clCommandEvent event(wxEVT_SSH_CHANNEL_WRITE_ERROR); handler->QueueEvent(event.Clone()); break; } else { - LOG_DEBUG(LOG) << "successfully sent signal:" << cmd.signal_prefix << "to ssh channel" << endl; + LOG_DEBUG(LOG()) << "successfully sent signal:" << cmd.signal_prefix << "to ssh channel" << endl; } } else { - LOG_WARNING(LOG) << "received unknown command." << endl; + LOG_WARNING(LOG()) << "received unknown command." << endl; } } } - LOG_DEBUG(LOG) << "helper thread is going down" << endl; + LOG_DEBUG(LOG()) << "helper thread is going down" << endl; }); return thr; } @@ -150,16 +150,16 @@ clSSHInteractiveChannel::Ptr_t clSSHInteractiveChannel::Create(wxEvtHandler* par wxString content = ssh::build_script_content(args, workingDir, envlist); wxString remote_script = "/tmp/clssh_" + FileUtils::NormaliseFilename(args[0]); - LOG_DEBUG(LOG) << "executing remote script:" << remote_script << endl; + LOG_DEBUG(LOG()) << "executing remote script:" << remote_script << endl; auto res = ssh::write_remote_file_content(ssh, remote_script, content); if(!res) { - LOG_WARNING(LOG) << "SSH failed to write remote file." << res.error_message() << endl; + LOG_WARNING(LOG()) << "SSH failed to write remote file." << res.error_message() << endl; return nullptr; } auto channel = ssh_channel_new(session); if(!channel) { - LOG_WARNING(LOG) << "Failed to allocate new ssh channel." << ssh_get_error(session) << endl; + LOG_WARNING(LOG()) << "Failed to allocate new ssh channel." << ssh_get_error(session) << endl; return nullptr; } @@ -167,7 +167,7 @@ clSSHInteractiveChannel::Ptr_t clSSHInteractiveChannel::Create(wxEvtHandler* par int rc = SSH_OK; rc = ssh_channel_open_session(channel); if(rc != SSH_OK) { - LOG_WARNING(LOG) << "Failed to open the session." << ssh_get_error(session) << endl; + LOG_WARNING(LOG()) << "Failed to open the session." << ssh_get_error(session) << endl; ssh_channel_free(channel); return nullptr; } @@ -175,7 +175,7 @@ clSSHInteractiveChannel::Ptr_t clSSHInteractiveChannel::Create(wxEvtHandler* par // request a shell rc = ssh_channel_request_shell(channel); if(rc != SSH_OK) { - LOG_WARNING(LOG) << "SSH request shell error." << ssh_get_error(session) << endl; + LOG_WARNING(LOG()) << "SSH request shell error." << ssh_get_error(session) << endl; ssh_channel_free(channel); return nullptr; } @@ -210,7 +210,7 @@ clSSHInteractiveChannel::clSSHInteractiveChannel(wxEvtHandler* parent, clSSH::Pt clSSHInteractiveChannel::~clSSHInteractiveChannel() { - LOG_DEBUG(LOG) << "Unbinding events" << endl; + LOG_DEBUG(LOG()) << "Unbinding events" << endl; Unbind(wxEVT_SSH_CHANNEL_WRITE_ERROR, &clSSHInteractiveChannel::OnChannelError, this); Unbind(wxEVT_SSH_CHANNEL_READ_ERROR, &clSSHInteractiveChannel::OnChannelError, this); Unbind(wxEVT_SSH_CHANNEL_READ_OUTPUT, &clSSHInteractiveChannel::OnChannelStdout, this); @@ -304,7 +304,7 @@ bool clSSHInteractiveChannel::WriteRaw(const std::string& buff) void clSSHInteractiveChannel::WaitForTerminate(wxString& output) { - LOG_ERROR(LOG) << "WaitForTerminate is not supported for interactive shell commands" << endl; + LOG_ERROR(LOG()) << "WaitForTerminate is not supported for interactive shell commands" << endl; } bool clSSHInteractiveChannel::WriteToConsole(const wxString& buff) { return Write(buff); } @@ -353,7 +353,7 @@ void clSSHInteractiveChannel::Signal(wxSignal sig) break; } if(!prefix) { - LOG_ERROR(LOG) << "unknown signal" << endl; + LOG_ERROR(LOG()) << "unknown signal" << endl; return; } @@ -363,20 +363,20 @@ void clSSHInteractiveChannel::Signal(wxSignal sig) void clSSHInteractiveChannel::ResumeAsyncReads() { - LOG_ERROR(LOG) << "ResumeAsyncReads is not supported for interactive shell commands" << endl; + LOG_ERROR(LOG()) << "ResumeAsyncReads is not supported for interactive shell commands" << endl; } void clSSHInteractiveChannel::SuspendAsyncReads() { - LOG_ERROR(LOG) << "SuspendAsyncReads is not supported for interactive shell commands" << endl; + LOG_ERROR(LOG()) << "SuspendAsyncReads is not supported for interactive shell commands" << endl; } void clSSHInteractiveChannel::OnChannelStdout(clCommandEvent& event) { - LOG_IF_DEBUG { LOG_DEBUG(LOG) << event.GetStringRaw() << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << event.GetStringRaw() << endl; } if(!m_waiting) { - LOG_DEBUG(LOG) << "sending wxEVT_ASYNC_PROCESS_OUTPUT event" << endl; + LOG_DEBUG(LOG()) << "sending wxEVT_ASYNC_PROCESS_OUTPUT event" << endl; clProcessEvent event_stdout{ wxEVT_ASYNC_PROCESS_OUTPUT }; event_stdout.SetProcess(nullptr); event_stdout.SetOutputRaw(event.GetStringRaw()); @@ -392,7 +392,7 @@ void clSSHInteractiveChannel::OnChannelStdout(clCommandEvent& event) m_waiting = false; // found the marker - LOG_DEBUG(LOG) << "found the marker" << endl; + LOG_DEBUG(LOG()) << "found the marker" << endl; // remove the marker from the input string wxString remainder = m_waitingBuffer.substr(where + marker.length()); @@ -403,11 +403,11 @@ void clSSHInteractiveChannel::OnChannelStdout(clCommandEvent& event) event_stdout.SetOutputRaw(StringUtils::ToStdString(remainder)); event_stdout.SetOutput(remainder); AddPendingEvent(event_stdout); - LOG_DEBUG(LOG) << "stdout (active): `" << remainder << "`" << endl; + LOG_DEBUG(LOG()) << "stdout (active): `" << remainder << "`" << endl; } m_waitingBuffer.clear(); } else { - LOG_DEBUG(LOG) << "stdout (waiting): `" << event.GetStringRaw() << "`" << endl; + LOG_DEBUG(LOG()) << "stdout (waiting): `" << event.GetStringRaw() << "`" << endl; } } } @@ -421,9 +421,9 @@ void clSSHInteractiveChannel::OnChannelStderr(clCommandEvent& event) event_stdout.SetOutputRaw(event.GetStringRaw()); event_stdout.SetOutput(event.GetStringRaw()); AddPendingEvent(event_stdout); - LOG_DEBUG(LOG) << "stderr (active): `" << event.GetStringRaw() << "`" << endl; + LOG_DEBUG(LOG()) << "stderr (active): `" << event.GetStringRaw() << "`" << endl; } else { - LOG_DEBUG(LOG) << "stderr (waiting): `" << event.GetStringRaw() << "`" << endl; + LOG_DEBUG(LOG()) << "stderr (waiting): `" << event.GetStringRaw() << "`" << endl; } } @@ -433,14 +433,14 @@ void clSSHInteractiveChannel::OnChannelClosed(clCommandEvent& event) clProcessEvent event_terminated{ wxEVT_ASYNC_PROCESS_TERMINATED }; event_terminated.SetProcess(nullptr); AddPendingEvent(event_terminated); - LOG_DEBUG(LOG) << "channel closed" << endl; + LOG_DEBUG(LOG()) << "channel closed" << endl; m_closeEventFired = true; } } void clSSHInteractiveChannel::OnChannelError(clCommandEvent& event) { - LOG_DEBUG(LOG) << "channel error." << ssh_get_error(m_ssh->GetSession()) << endl; + LOG_DEBUG(LOG()) << "channel error." << ssh_get_error(m_ssh->GetSession()) << endl; clProcessEvent event_terminated{ wxEVT_ASYNC_PROCESS_TERMINATED }; event_terminated.SetProcess(nullptr); AddPendingEvent(event_terminated); diff --git a/Plugin/LSP/LSPNetworkRemoteSTDIO.cpp b/Plugin/LSP/LSPNetworkRemoteSTDIO.cpp index eb46171883..cf29197514 100644 --- a/Plugin/LSP/LSPNetworkRemoteSTDIO.cpp +++ b/Plugin/LSP/LSPNetworkRemoteSTDIO.cpp @@ -30,11 +30,11 @@ void LSPNetworkRemoteSTDIO::DoClose() void LSPNetworkRemoteSTDIO::DoStartRemoteProcess() { - LOG_DEBUG(LOG) << "Starting remote process:" << endl; - LOG_DEBUG(LOG) << m_startupInfo.GetLspServerCommand() << endl; - LOG_DEBUG(LOG) << m_startupInfo.GetWorkingDirectory() << endl; + LOG_DEBUG(LOG()) << "Starting remote process:" << endl; + LOG_DEBUG(LOG()) << m_startupInfo.GetLspServerCommand() << endl; + LOG_DEBUG(LOG()) << m_startupInfo.GetWorkingDirectory() << endl; for(const auto& p : m_startupInfo.GetEnv()) { - LOG_DEBUG(LOG) << p.first << "=" << p.second << endl; + LOG_DEBUG(LOG()) << p.first << "=" << p.second << endl; } m_process = clRemoteHost::Instance()->run_interactive_process( @@ -48,9 +48,9 @@ void LSPNetworkRemoteSTDIO::DoStartRemoteProcess() void LSPNetworkRemoteSTDIO::Send(const std::string& data) { - LOG_IF_DEBUG { LOG_DEBUG(LOG) << ">" << data << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << ">" << data << endl; } if(!m_process) { - LOG_WARNING(LOG) << "remote server is not running" << endl; + LOG_WARNING(LOG()) << "remote server is not running" << endl; return; } m_process->WriteRaw(data); @@ -88,7 +88,7 @@ void LSPNetworkRemoteSTDIO::OnProcessStderr(clProcessEvent& event) void LSPNetworkRemoteSTDIO::BindEvents() { if(!m_process) { - LOG_WARNING(LOG) << "failed to bind events. process is not running" << endl; + LOG_WARNING(LOG()) << "failed to bind events. process is not running" << endl; return; } if(!m_eventsBound) { diff --git a/Plugin/clRemoteHost.cpp b/Plugin/clRemoteHost.cpp index 85a41ee43c..c43559a3c8 100644 --- a/Plugin/clRemoteHost.cpp +++ b/Plugin/clRemoteHost.cpp @@ -95,7 +95,7 @@ clSSH::Ptr_t clRemoteHost::CreateSession(const wxString& account_name) // create new session auto account = SSHAccountInfo::LoadAccount(account_name); if(account.GetHost().empty()) { - LOG_WARNING(LOG) << "could not find account:" << account_name << endl; + LOG_WARNING(LOG()) << "could not find account:" << account_name << endl; return nullptr; } @@ -111,11 +111,11 @@ clSSH::Ptr_t clRemoteHost::CreateSession(const wxString& account_name) } ssh_session->Login(); } catch(clException& e) { - LOG_ERROR(LOG) << "Failed to open ssh channel to account:" << account.GetAccountName() << "." << e.What() + LOG_ERROR(LOG()) << "Failed to open ssh channel to account:" << account.GetAccountName() << "." << e.What() << endl; return nullptr; } - LOG_DEBUG(LOG) << "Initializing for account:" << account_name << "completed successfully" << endl; + LOG_DEBUG(LOG()) << "Initializing for account:" << account_name << "completed successfully" << endl; return ssh_session; } @@ -140,10 +140,10 @@ void clRemoteHost::OnCommandStderr(clProcessEvent& event) { const std::string& output = event.GetStringRaw(); if(m_callbacks.empty()) { - LOG_WARNING(LOG) << "no callback found for command output" << endl; + LOG_WARNING(LOG()) << "no callback found for command output" << endl; return; } - LOG_DEBUG(LOG) << "stderr:" << event.GetStringRaw().size() << "bytes" << endl; + LOG_DEBUG(LOG()) << "stderr:" << event.GetStringRaw().size() << "bytes" << endl; // call the callback m_callbacks.front().first(output, clRemoteCommandStatus::STDERR); } @@ -152,10 +152,10 @@ void clRemoteHost::OnCommandStdout(clProcessEvent& event) { const std::string& output = event.GetStringRaw(); if(m_callbacks.empty()) { - LOG_WARNING(LOG) << "no callback found for command output" << endl; + LOG_WARNING(LOG()) << "no callback found for command output" << endl; return; } - LOG_DEBUG(LOG) << "stdout:" << event.GetStringRaw().size() << "bytes" << endl; + LOG_DEBUG(LOG()) << "stdout:" << event.GetStringRaw().size() << "bytes" << endl; // call the callback m_callbacks.front().first(output, clRemoteCommandStatus::STDOUT); } @@ -163,12 +163,12 @@ void clRemoteHost::OnCommandStdout(clProcessEvent& event) void clRemoteHost::OnCommandCompleted(clProcessEvent& event) { if(m_callbacks.empty()) { - LOG_WARNING(LOG) << "no callback found for command output" << endl; + LOG_WARNING(LOG()) << "no callback found for command output" << endl; return; } // call the callback and consume it from the queue - LOG_DEBUG(LOG) << "command completed. exit status:" << event.GetInt() << endl; + LOG_DEBUG(LOG()) << "command completed. exit status:" << event.GetInt() << endl; m_callbacks.front().first("", event.GetInt() == 0 ? clRemoteCommandStatus::DONE : clRemoteCommandStatus::DONE_WITH_ERROR); m_callbacks.erase(m_callbacks.begin()); @@ -180,11 +180,11 @@ IProcess::Ptr_t clRemoteHost::run_interactive_process(wxEvtHandler* parent, cons // create new ssh session auto ssh_session = CreateSession(m_activeAccount); if(!ssh_session) { - LOG_ERROR(LOG) << "no ssh session available" << endl; + LOG_ERROR(LOG()) << "no ssh session available" << endl; return IProcess::Ptr_t{}; } - LOG_DEBUG(LOG) << "Launching remote process:" << command << endl; + LOG_DEBUG(LOG()) << "Launching remote process:" << command << endl; std::vector argv{ command.begin(), command.end() }; IProcess::Ptr_t proc( diff --git a/Plugin/cl_remote_executor.cpp b/Plugin/cl_remote_executor.cpp index 8596252fbe..07eeda1b5d 100644 --- a/Plugin/cl_remote_executor.cpp +++ b/Plugin/cl_remote_executor.cpp @@ -34,7 +34,7 @@ IProcess::Ptr_t clRemoteExecutor::try_execute(const clRemoteExecutor::Cmd& cmd) { auto ssh_session = clRemoteHost::Instance()->TakeSession(); if(!ssh_session) { - LOG_WARNING(LOG) << "SSH session is not opened" << endl; + LOG_WARNING(LOG()) << "SSH session is not opened" << endl; return nullptr; } @@ -44,7 +44,7 @@ IProcess::Ptr_t clRemoteExecutor::try_execute(const clRemoteExecutor::Cmd& cmd) ssh_session, [](clSSH::Ptr_t ssh) { clRemoteHost::Instance()->AddSshSession(ssh); }, this, command, true); if(!proc) { - LOG_ERROR(LOG) << "failed to start remote command:" << command << endl; + LOG_ERROR(LOG()) << "failed to start remote command:" << command << endl; return nullptr; } return proc; @@ -54,7 +54,7 @@ void clRemoteExecutor::OnChannelStdout(clCommandEvent& event) { clProcessEvent output_event{ wxEVT_ASYNC_PROCESS_OUTPUT }; output_event.SetStringRaw(event.GetStringRaw()); - LOG_DEBUG(LOG) << "stdout read:" << event.GetStringRaw().size() << "bytes" << endl; + LOG_DEBUG(LOG()) << "stdout read:" << event.GetStringRaw().size() << "bytes" << endl; ProcessEvent(output_event); } @@ -62,13 +62,13 @@ void clRemoteExecutor::OnChannelStderr(clCommandEvent& event) { clProcessEvent output_event{ wxEVT_ASYNC_PROCESS_STDERR }; output_event.SetStringRaw(event.GetStringRaw()); - LOG_DEBUG(LOG) << "stderr read:" << event.GetStringRaw().size() << "bytes" << endl; + LOG_DEBUG(LOG()) << "stderr read:" << event.GetStringRaw().size() << "bytes" << endl; ProcessEvent(output_event); } void clRemoteExecutor::OnChannelClosed(clCommandEvent& event) { - LOG_DEBUG(LOG) << "remote channel closed" << endl; + LOG_DEBUG(LOG()) << "remote channel closed" << endl; clProcessEvent output_event{ wxEVT_ASYNC_PROCESS_TERMINATED }; output_event.SetInt(event.GetInt()); diff --git a/Plugin/wxTerminalCtrl/wxTerminalAnsiEscapeHandler.cpp b/Plugin/wxTerminalCtrl/wxTerminalAnsiEscapeHandler.cpp index af4e1e41dd..67ca994815 100644 --- a/Plugin/wxTerminalCtrl/wxTerminalAnsiEscapeHandler.cpp +++ b/Plugin/wxTerminalCtrl/wxTerminalAnsiEscapeHandler.cpp @@ -990,7 +990,7 @@ wxHandlResultStringView before_first(wxStringView sv, wxChar ch) void wxTerminalAnsiEscapeHandler::handle_sgr(wxStringView sv, wxTerminalAnsiRendererInterface* renderer) { - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "SGR:" << wxString(sv.data(), sv.length()) << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "SGR:" << wxString(sv.data(), sv.length()) << endl; } if(sv.empty()) { // handle like reset diff --git a/Plugin/wxTerminalCtrl/wxTerminalAnsiRendererInterface.cpp b/Plugin/wxTerminalCtrl/wxTerminalAnsiRendererInterface.cpp index 4464343463..f71fdce7e9 100644 --- a/Plugin/wxTerminalCtrl/wxTerminalAnsiRendererInterface.cpp +++ b/Plugin/wxTerminalCtrl/wxTerminalAnsiRendererInterface.cpp @@ -9,63 +9,63 @@ wxTerminalAnsiRendererInterface::wxTerminalAnsiRendererInterface() {} wxTerminalAnsiRendererInterface::~wxTerminalAnsiRendererInterface() {} -void wxTerminalAnsiRendererInterface::Bell() { LOG_DEBUG(LOG) << "Bell!" << endl; } -void wxTerminalAnsiRendererInterface::Backspace() { LOG_DEBUG(LOG) << "Backspace!" << endl; } -void wxTerminalAnsiRendererInterface::Tab() { LOG_DEBUG(LOG) << "Tab!" << endl; } -void wxTerminalAnsiRendererInterface::LineFeed() { LOG_DEBUG(LOG) << "Line Feed!" << endl; } -void wxTerminalAnsiRendererInterface::FormFeed() { LOG_DEBUG(LOG) << "Form Feed!" << endl; } -void wxTerminalAnsiRendererInterface::CarriageReturn() { LOG_DEBUG(LOG) << "CR!" << endl; } +void wxTerminalAnsiRendererInterface::Bell() { LOG_DEBUG(LOG()) << "Bell!" << endl; } +void wxTerminalAnsiRendererInterface::Backspace() { LOG_DEBUG(LOG()) << "Backspace!" << endl; } +void wxTerminalAnsiRendererInterface::Tab() { LOG_DEBUG(LOG()) << "Tab!" << endl; } +void wxTerminalAnsiRendererInterface::LineFeed() { LOG_DEBUG(LOG()) << "Line Feed!" << endl; } +void wxTerminalAnsiRendererInterface::FormFeed() { LOG_DEBUG(LOG()) << "Form Feed!" << endl; } +void wxTerminalAnsiRendererInterface::CarriageReturn() { LOG_DEBUG(LOG()) << "CR!" << endl; } void wxTerminalAnsiRendererInterface::AddString(wxStringView str) {} void wxTerminalAnsiRendererInterface::EraseCharacter(int) {} void wxTerminalAnsiRendererInterface::MoveCaret(long n, wxDirection direction) { - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "MoveCaret:" << n << ". Direction:" << (int)direction << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "MoveCaret:" << n << ". Direction:" << (int)direction << endl; } } void wxTerminalAnsiRendererInterface::SetCaretX(long n) { m_pos.x = (n - 1); // we are 0 based m_pos.x = wxMax(m_pos.x, 0); - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "SetCaretX(" << n << ")" << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "SetCaretX(" << n << ")" << endl; } } void wxTerminalAnsiRendererInterface::SetCaretY(long n) { m_pos.y = (n - 1); // we are 0 based m_pos.y = wxMax(m_pos.y, 0); - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "SetCaretY(" << n << ")" << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "SetCaretY(" << n << ")" << endl; } } void wxTerminalAnsiRendererInterface::ClearLine(size_t dir) { - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "ClearLine" << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "ClearLine" << endl; } } void wxTerminalAnsiRendererInterface::ClearDisplay(size_t dir) { - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "ClearDisplay" << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "ClearDisplay" << endl; } } void wxTerminalAnsiRendererInterface::SetWindowTitle(wxStringView window_title) { LOG_IF_DEBUG { - LOG_DEBUG(LOG) << "SetWindowTitle(" << wxString(window_title.data(), window_title.length()) << ")" << endl; + LOG_DEBUG(LOG()) << "SetWindowTitle(" << wxString(window_title.data(), window_title.length()) << ")" << endl; } } void wxTerminalAnsiRendererInterface::ResetStyle() { m_curAttr = m_defaultAttr; - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "ResetStyle" << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "ResetStyle" << endl; } } void wxTerminalAnsiRendererInterface::SetTextColour(const wxColour& col) { if(col.IsOk()) { - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "SetTextColour(" << col << ")" << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "SetTextColour(" << col << ")" << endl; } m_curAttr.SetTextColour(col); } else { - LOG_IF_DEBUG { LOG_DEBUG(LOG) << "SetTextColour(NullColour)" << endl; } + LOG_IF_DEBUG { LOG_DEBUG(LOG()) << "SetTextColour(NullColour)" << endl; } m_curAttr.SetTextColour(m_defaultAttr.GetTextColour()); } } diff --git a/Plugin/wxTerminalCtrl/wxTerminalCtrl.cpp b/Plugin/wxTerminalCtrl/wxTerminalCtrl.cpp index 7a1c618ddf..4634e48ce0 100644 --- a/Plugin/wxTerminalCtrl/wxTerminalCtrl.cpp +++ b/Plugin/wxTerminalCtrl/wxTerminalCtrl.cpp @@ -99,7 +99,7 @@ void wxTerminalCtrl::StartShell() penv = &env; #endif - LOG_DEBUG(TERM_LOG) << "Starting shell process:" << shell_exec << endl; + LOG_DEBUG(TERM_LOG()) << "Starting shell process:" << shell_exec << endl; if(m_shellCommand == "bash") { m_shell = ::CreateAsyncProcess(this, shell_exec + " --login -i", IProcessRawOutput, wxEmptyString, penv); } else { @@ -107,17 +107,17 @@ void wxTerminalCtrl::StartShell() } if(m_shell) { - LOG_DEBUG(TERM_LOG) << "Setting working directory to:" << m_startingDirectory << endl; + LOG_DEBUG(TERM_LOG()) << "Setting working directory to:" << m_startingDirectory << endl; if(!m_startingDirectory.empty()) { // now that we have a shell, set the working directory SetTerminalWorkingDirectory(m_startingDirectory); } - LOG_DEBUG(TERM_LOG) << "Successfully started shell terminal" << endl; + LOG_DEBUG(TERM_LOG()) << "Successfully started shell terminal" << endl; wxTerminalEvent readyEvent(wxEVT_TERMINAL_CTRL_READY); readyEvent.SetEventObject(this); GetEventHandler()->AddPendingEvent(readyEvent); } else { - LOG_ERROR(TERM_LOG) << "Failed to launch shell terminal:" << shell_exec << endl; + LOG_ERROR(TERM_LOG()) << "Failed to launch shell terminal:" << shell_exec << endl; } m_inputCtrl->SetFocus(); } @@ -127,7 +127,7 @@ void wxTerminalCtrl::Run(const wxString& command) if(!m_shell) { return; } - LOG_DEBUG(TERM_LOG) << "-->" << command << endl; + LOG_DEBUG(TERM_LOG()) << "-->" << command << endl; m_shell->WriteRaw(command + "\n"); wxStringView sv{ command.wc_str(), command.length() }; @@ -328,7 +328,7 @@ void wxTerminalCtrl::ProcessOutputBuffer() } wxStringView sv{ m_processOutput.data(), m_processOutput.length() }; - LOG_IF_DEBUG { LOG_DEBUG(TERM_LOG) << "<--" << wxString(sv.data(), sv.length()) << endl; } + LOG_IF_DEBUG { LOG_DEBUG(TERM_LOG()) << "<--" << wxString(sv.data(), sv.length()) << endl; } AppendText(sv); diff --git a/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp b/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp index d5e6c631d3..8f9b00a2e5 100644 --- a/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp +++ b/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp @@ -16,12 +16,9 @@ #include "wxTerminalCtrl.h" #include "wxTerminalInputCtrl.hpp" -#include - -INITIALISE_MODULE_LOG(LOG, "AnsiEscapeHandler", "ansi_escape_parser.log"); - #include #include +#include #include namespace