Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion wiring/src/spark_wiring_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include <cinttypes>
#include <memory>

#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
Expand Down Expand Up @@ -472,6 +472,12 @@ int spark::detail::LogFilter::nodeIndex(const Vector<Node> &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) {
Expand Down Expand Up @@ -535,6 +541,12 @@ 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
Expand Down Expand Up @@ -629,7 +641,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
Expand Down