From f0ec07fd2a0354c67d2be380cd1d906f62d53c5c Mon Sep 17 00:00:00 2001 From: Marco Randazzo Date: Mon, 22 Nov 2021 16:54:23 +0100 Subject: [PATCH] LogForwarder: now using yarp::os::PortWriterBuffer --- doc/release/master/fix_logFowarder_lost_msgs.md | 10 ++++++++++ src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp | 7 ++++--- src/libYARP_os/src/yarp/os/impl/LogForwarder.h | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 doc/release/master/fix_logFowarder_lost_msgs.md diff --git a/doc/release/master/fix_logFowarder_lost_msgs.md b/doc/release/master/fix_logFowarder_lost_msgs.md new file mode 100644 index 00000000000..55a8c10e772 --- /dev/null +++ b/doc/release/master/fix_logFowarder_lost_msgs.md @@ -0,0 +1,10 @@ +fix_logForwarder_lost_msgs {#master} +----------------------- + +## Libraries + +### `os` + +#### `Log` + +* LogForwarder: now using yarp::os::PortWriterBuffer to prevent message loss \ No newline at end of file diff --git a/src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp b/src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp index 8d5e0c533d8..b7d214a177e 100644 --- a/src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp +++ b/src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp @@ -46,8 +46,9 @@ yarp::os::impl::LogForwarder::LogForwarder() if (!outputPort.open(logPortName)) { printf("LogForwarder error while opening port %s\n", logPortName.c_str()); } - outputPort.enableBackgroundWrite(true); + outputPort.addOutput("/yarplogger", "fast_tcp"); + outputPort_buffer.attach(outputPort); started = true; } @@ -55,12 +56,12 @@ yarp::os::impl::LogForwarder::LogForwarder() void yarp::os::impl::LogForwarder::forward(const std::string& message) { mutex.lock(); - static Bottle b; + Bottle& b = outputPort_buffer.get(); b.clear(); std::string port = "[" + outputPort.getName() + "]"; b.addString(port); b.addString(message); - outputPort.write(b); + outputPort_buffer.write(); mutex.unlock(); } diff --git a/src/libYARP_os/src/yarp/os/impl/LogForwarder.h b/src/libYARP_os/src/yarp/os/impl/LogForwarder.h index dd9f8ef3895..5a700da3029 100644 --- a/src/libYARP_os/src/yarp/os/impl/LogForwarder.h +++ b/src/libYARP_os/src/yarp/os/impl/LogForwarder.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -31,6 +32,7 @@ class YARP_os_impl_API LogForwarder std::mutex mutex; yarp::os::Port outputPort; + yarp::os::PortWriterBuffer outputPort_buffer; static bool started; };