From 999211bf2a901f033d501d6158b320696f4249d9 Mon Sep 17 00:00:00 2001 From: Mateusz Daniluk <121170681+VeithMetro@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:34:13 +0200 Subject: [PATCH] [Messaging] Adding a functionality to the MessageControl plugin to handle redirected standard out and error (#255) * Adding factories for the two new message types (std out and error) * Changing the factories to match the new message type * Changing the factory name in the constructor * Changing the Output methods to use Format() method from ConsoleStandardOut class * Adding a test printfs * Cleaning the testing prints * Adding operational streams to JSON::Convert and optimizing it to have less conditions --- MessageControl/MessageControl.cpp | 2 ++ MessageControl/MessageControl.h | 1 + MessageControl/MessageOutput.cpp | 40 ++++++++----------------------- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/MessageControl/MessageControl.cpp b/MessageControl/MessageControl.cpp index d28304be..eef8ae6b 100644 --- a/MessageControl/MessageControl.cpp +++ b/MessageControl/MessageControl.cpp @@ -73,11 +73,13 @@ namespace WPEFramework { , _tracingFactory() , _loggingFactory() , _warningReportingFactory() + , _operationalStreamFactory() { _client.AddInstance(0); _client.AddFactory(Core::Messaging::Metadata::type::TRACING, &_tracingFactory); _client.AddFactory(Core::Messaging::Metadata::type::LOGGING, &_loggingFactory); _client.AddFactory(Core::Messaging::Metadata::type::REPORTING, &_warningReportingFactory); + _client.AddFactory(Core::Messaging::Metadata::type::OPERATIONAL_STREAM, &_operationalStreamFactory); } const string MessageControl::Initialize(PluginHost::IShell* service) diff --git a/MessageControl/MessageControl.h b/MessageControl/MessageControl.h index e4c12246..93a90ca1 100644 --- a/MessageControl/MessageControl.h +++ b/MessageControl/MessageControl.h @@ -442,6 +442,7 @@ namespace Plugin { Messaging::TraceFactoryType _tracingFactory; Messaging::TraceFactoryType _loggingFactory; Messaging::TraceFactoryType _warningReportingFactory; + Messaging::TraceFactoryType _operationalStreamFactory; Cleanups _cleaning; }; diff --git a/MessageControl/MessageOutput.cpp b/MessageControl/MessageOutput.cpp index 430bea0a..9a71a53c 100644 --- a/MessageControl/MessageOutput.cpp +++ b/MessageControl/MessageOutput.cpp @@ -35,7 +35,7 @@ namespace Publishers { void ConsoleOutput::Message(const Core::Messaging::MessageInfo& metadata, const string& text) /* override */ { - std::cout << _convertor.Convert(metadata, text); + Messaging::ConsoleStandardOut::Instance().Format(_convertor.Convert(metadata, text).c_str()); } void SyslogOutput::Message(const Core::Messaging::MessageInfo& metadata, const string& text) /* override */ @@ -43,7 +43,7 @@ namespace Publishers { #ifndef __WINDOWS__ syslog(LOG_NOTICE, _T("%s"), _convertor.Convert(metadata, text).c_str()); #else - printf(_T("%s"), _convertor.Convert(metadata, text).c_str()); + Messaging::ConsoleStandardOut::Instance().Format(_convertor.Convert(metadata, text).c_str()); #endif } @@ -69,17 +69,17 @@ namespace Publishers { data.Module = metadata.Module(); } + const Core::Time now(metadata.TimeStamp()); + if ((AsNumber(options) & AsNumber(ExtraOutputOptions::INCLUDINGDATE)) != 0) { + data.Time = now.ToRFC1123(true); + } + else { + data.Time = now.ToTimeOnly(true); + } + if (metadata.Type() == Core::Messaging::Metadata::type::TRACING) { ASSERT(dynamic_cast(&metadata) != nullptr); const Core::Messaging::IStore::Tracing& trace = static_cast(metadata); - const Core::Time now(trace.TimeStamp()); - - if ((AsNumber(options) & AsNumber(ExtraOutputOptions::INCLUDINGDATE)) != 0) { - data.Time = now.ToRFC1123(true); - } - else { - data.Time = now.ToTimeOnly(true); - } if ((AsNumber(options) & AsNumber(ExtraOutputOptions::FILENAME)) != 0) { data.FileName = trace.FileName(); @@ -93,29 +93,9 @@ namespace Publishers { data.ClassName = trace.ClassName(); } } - else if (metadata.Type() == Core::Messaging::Metadata::type::LOGGING) { - ASSERT(dynamic_cast(&metadata) != nullptr); - const Core::Messaging::IStore::Logging& log = static_cast(metadata); - const Core::Time now(log.TimeStamp()); - - if ((AsNumber(options) & AsNumber(ExtraOutputOptions::INCLUDINGDATE)) != 0) { - data.Time = now.ToRFC1123(true); - } - else { - data.Time = now.ToTimeOnly(true); - } - } else if (metadata.Type() == Core::Messaging::Metadata::type::REPORTING) { ASSERT(dynamic_cast(&metadata) != nullptr); const Core::Messaging::IStore::WarningReporting& report = static_cast(metadata); - const Core::Time now(report.TimeStamp()); - - if ((AsNumber(options) & AsNumber(ExtraOutputOptions::INCLUDINGDATE)) != 0) { - data.Time = now.ToRFC1123(true); - } - else { - data.Time = now.ToTimeOnly(true); - } if ((AsNumber(options) & AsNumber(ExtraOutputOptions::CALLSIGN)) != 0) { data.Callsign = report.Callsign();