Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logger lost messages #2767

Closed
Closed
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions doc/release/master/fix_logFowarder_lost_msgs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fix_logForwarder_lost_msgs {#master}
-----------------------

## Libraries

### `os`

#### `Log`

* LogForwarder: now using yarp::os::PortWriterBuffer to prevent message loss
7 changes: 4 additions & 3 deletions src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@ 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;
}

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();
}

Expand Down
2 changes: 2 additions & 0 deletions src/libYARP_os/src/yarp/os/impl/LogForwarder.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <yarp/os/api.h>

#include <yarp/os/Port.h>
#include <yarp/os/PortWriterBuffer.h>

#include <mutex>
#include <string>
Expand All @@ -31,6 +32,7 @@ class YARP_os_impl_API LogForwarder

std::mutex mutex;
yarp::os::Port outputPort;
yarp::os::PortWriterBuffer<yarp::os::Bottle> outputPort_buffer;
static bool started;
};

Expand Down