From 9f0e4ddde7003da6fd23fa47958c87e04ea4244c Mon Sep 17 00:00:00 2001 From: Sergey Polyakov Date: Mon, 20 May 2019 22:47:44 +0200 Subject: [PATCH 1/2] Do not mix logging and serial console output --- wiring/src/spark_wiring_logging.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wiring/src/spark_wiring_logging.cpp b/wiring/src/spark_wiring_logging.cpp index feee69531e..539ffc31ae 100644 --- a/wiring/src/spark_wiring_logging.cpp +++ b/wiring/src/spark_wiring_logging.cpp @@ -26,9 +26,9 @@ #include #include +#include "spark_wiring_network.h" #include "spark_wiring_usbserial.h" #include "spark_wiring_usartserial.h" - #include "spark_wiring_interrupts.h" // Uncomment to enable logging in interrupt handlers @@ -472,6 +472,10 @@ int spark::detail::LogFilter::nodeIndex(const Vector &nodes, const char *n // spark::StreamLogHandler void spark::StreamLogHandler::logMessage(const char *msg, LogLevel level, const char *category, const LogAttributes &attr) { + // TODO: Move this check to a base class (see also JSONStreamLogHandler::logMessage()) + if (stream_ == &Serial && Network.listening()) { + return; // Do not mix logging and serial console output + } const char *s = nullptr; // Timestamp if (attr.has_time) { @@ -535,6 +539,10 @@ void spark::StreamLogHandler::logMessage(const char *msg, LogLevel level, const // spark::JSONStreamLogHandler void spark::JSONStreamLogHandler::logMessage(const char *msg, LogLevel level, const char *category, const LogAttributes &attr) { + // TODO: Move this check to a base class (see also StreamLogHandler::logMessage()) + if (this->stream() == &Serial && Network.listening()) { + return; // Do not mix logging and serial console output + } JSONStreamWriter json(*this->stream()); json.beginObject(); // Level @@ -629,7 +637,10 @@ Print* spark::DefaultOutputStreamFactory::createStream(const char *type, const J void spark::DefaultOutputStreamFactory::destroyStream(Print *stream) { #if PLATFORM_ID != 3 if (stream == &Serial) { + // FIXME: Uninitializing Serial detaches a Gen 3 device from the host +#if !HAL_PLATFORM_NRF52840 Serial.end(); +#endif return; } #if Wiring_USBSerial1 From 0f44ec08b853c5454e4c8a9a1242f945c86f2d12 Mon Sep 17 00:00:00 2001 From: Sergey Polyakov Date: Mon, 9 Sep 2019 13:05:59 +0200 Subject: [PATCH 2/2] Fix unit tests --- wiring/src/spark_wiring_logging.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wiring/src/spark_wiring_logging.cpp b/wiring/src/spark_wiring_logging.cpp index 539ffc31ae..5c25cc9259 100644 --- a/wiring/src/spark_wiring_logging.cpp +++ b/wiring/src/spark_wiring_logging.cpp @@ -473,9 +473,11 @@ int spark::detail::LogFilter::nodeIndex(const Vector &nodes, const char *n // spark::StreamLogHandler void spark::StreamLogHandler::logMessage(const char *msg, LogLevel level, const char *category, const LogAttributes &attr) { // TODO: Move this check to a base class (see also JSONStreamLogHandler::logMessage()) +#if PLATFORM_ID != PLATFORM_GCC if (stream_ == &Serial && Network.listening()) { return; // Do not mix logging and serial console output } +#endif const char *s = nullptr; // Timestamp if (attr.has_time) { @@ -540,9 +542,11 @@ void spark::StreamLogHandler::logMessage(const char *msg, LogLevel level, const // spark::JSONStreamLogHandler void spark::JSONStreamLogHandler::logMessage(const char *msg, LogLevel level, const char *category, const LogAttributes &attr) { // TODO: Move this check to a base class (see also StreamLogHandler::logMessage()) +#if PLATFORM_ID != PLATFORM_GCC if (this->stream() == &Serial && Network.listening()) { return; // Do not mix logging and serial console output } +#endif JSONStreamWriter json(*this->stream()); json.beginObject(); // Level