mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Move piping stream lines to the log to common
This commit is contained in:
@@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#ifdef __WINE__
|
|
||||||
#include "../wine-host/boost-fix.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <vestige/aeffectx.h>
|
#include <vestige/aeffectx.h>
|
||||||
|
|
||||||
#include <boost/process/environment.hpp>
|
#include <boost/process/environment.hpp>
|
||||||
|
|||||||
@@ -20,6 +20,31 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
|
#ifdef __WINE__
|
||||||
|
#include "../wine-host/boost-fix.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/asio/read_until.hpp>
|
||||||
|
#include <boost/asio/streambuf.hpp>
|
||||||
|
#include <boost/process/async_pipe.hpp>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boost 1.72 was released with a known breaking bug caused by a missing
|
||||||
|
* typedef: https://github.com/boostorg/process/issues/116.
|
||||||
|
*
|
||||||
|
* Luckily this is easy to fix since it's not really possible to downgrade Boost
|
||||||
|
* as it would break other applications.
|
||||||
|
*
|
||||||
|
* Check if this is still needed for other distros after Arch starts packaging
|
||||||
|
* Boost 1.73.
|
||||||
|
*/
|
||||||
|
class patched_async_pipe : public boost::process::async_pipe {
|
||||||
|
public:
|
||||||
|
using boost::process::async_pipe::async_pipe;
|
||||||
|
|
||||||
|
typedef typename handle_type::executor_type executor_type;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Super basic logging facility meant for debugging malfunctioning VST
|
* Super basic logging facility meant for debugging malfunctioning VST
|
||||||
* plugins. This is also used to redirect the output of the Wine process
|
* plugins. This is also used to redirect the output of the Wine process
|
||||||
@@ -112,6 +137,36 @@ class Logger {
|
|||||||
*/
|
*/
|
||||||
void log_trace(const std::string& message);
|
void log_trace(const std::string& message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write output from an async pipe to the log on a line by line basis.
|
||||||
|
* Useful for logging the Wine process's STDOUT and STDERR streams.
|
||||||
|
*
|
||||||
|
* @param pipe Some Boost.Asio stream that can be read from. Probably either
|
||||||
|
* `patched_async_pipe` or a stream descriptor.
|
||||||
|
* @param buffer The buffer that will be used to read from `pipe`.
|
||||||
|
* @param prefix Text to prepend to the line before writing to the log.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
void async_log_pipe_lines(T& pipe,
|
||||||
|
boost::asio::streambuf& buffer,
|
||||||
|
std::string prefix = "") {
|
||||||
|
boost::asio::async_read_until(
|
||||||
|
pipe, buffer, '\n',
|
||||||
|
[&, prefix](const boost::system::error_code& error, size_t) {
|
||||||
|
// When we get an error code then that likely means that the
|
||||||
|
// pipe has been clsoed and we have reached the end of the file
|
||||||
|
if (error.failed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
std::getline(std::istream(&buffer), line);
|
||||||
|
log(prefix + line);
|
||||||
|
|
||||||
|
async_log_pipe_lines(pipe, buffer, prefix);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The verbosity level of this logger instance. Based on this certain
|
* The verbosity level of this logger instance. Based on this certain
|
||||||
* messages may or may not be shown.
|
* messages may or may not be shown.
|
||||||
|
|||||||
@@ -61,28 +61,8 @@ HostProcess::HostProcess(boost::asio::io_context& io_context, Logger& logger)
|
|||||||
// Print the Wine host's STDOUT and STDERR streams to the log file. This
|
// Print the Wine host's STDOUT and STDERR streams to the log file. This
|
||||||
// should be done before trying to accept the sockets as otherwise we will
|
// should be done before trying to accept the sockets as otherwise we will
|
||||||
// miss all output.
|
// miss all output.
|
||||||
async_log_pipe_lines(stdout_pipe, stdout_buffer, "[Wine STDOUT] ");
|
logger.async_log_pipe_lines(stdout_pipe, stdout_buffer, "[Wine STDOUT] ");
|
||||||
async_log_pipe_lines(stderr_pipe, stderr_buffer, "[Wine STDERR] ");
|
logger.async_log_pipe_lines(stderr_pipe, stderr_buffer, "[Wine STDERR] ");
|
||||||
}
|
|
||||||
|
|
||||||
void HostProcess::async_log_pipe_lines(patched_async_pipe& pipe,
|
|
||||||
boost::asio::streambuf& buffer,
|
|
||||||
std::string prefix) {
|
|
||||||
boost::asio::async_read_until(
|
|
||||||
pipe, buffer, '\n',
|
|
||||||
[&, prefix](const boost::system::error_code& error, size_t) {
|
|
||||||
// When we get an error code then that likely means that the pipe
|
|
||||||
// has been clsoed and we have reached the end of the file
|
|
||||||
if (error.failed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string line;
|
|
||||||
std::getline(std::istream(&buffer), line);
|
|
||||||
logger.log(prefix + line);
|
|
||||||
|
|
||||||
async_log_pipe_lines(pipe, buffer, prefix);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IndividualHost::IndividualHost(boost::asio::io_context& io_context,
|
IndividualHost::IndividualHost(boost::asio::io_context& io_context,
|
||||||
|
|||||||
@@ -81,18 +81,6 @@ class HostProcess {
|
|||||||
patched_async_pipe stderr_pipe;
|
patched_async_pipe stderr_pipe;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* Write output from an async pipe to the log on a line by line basis.
|
|
||||||
* Useful for logging the Wine process's STDOUT and STDERR streams.
|
|
||||||
*
|
|
||||||
* @param pipe The pipe to read from.
|
|
||||||
* @param buffer The stream buffer to write to.
|
|
||||||
* @param prefix Text to prepend to the line before writing to the log.
|
|
||||||
*/
|
|
||||||
void async_log_pipe_lines(patched_async_pipe& pipe,
|
|
||||||
boost::asio::streambuf& buffer,
|
|
||||||
std::string prefix = "");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger the Wine output will be written to.
|
* The logger the Wine output will be written to.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,29 +18,11 @@
|
|||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
#include <boost/process/async_pipe.hpp>
|
|
||||||
#include <boost/process/environment.hpp>
|
#include <boost/process/environment.hpp>
|
||||||
|
|
||||||
#include "../common/configuration.h"
|
#include "../common/configuration.h"
|
||||||
#include "../common/plugins.h"
|
#include "../common/plugins.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* Boost 1.72 was released with a known breaking bug caused by a missing
|
|
||||||
* typedef: https://github.com/boostorg/process/issues/116.
|
|
||||||
*
|
|
||||||
* Luckily this is easy to fix since it's not really possible to downgrade Boost
|
|
||||||
* as it would break other applications.
|
|
||||||
*
|
|
||||||
* Check if this is still needed for other distros after Arch starts packaging
|
|
||||||
* Boost 1.73.
|
|
||||||
*/
|
|
||||||
class patched_async_pipe : public boost::process::async_pipe {
|
|
||||||
public:
|
|
||||||
using boost::process::async_pipe::async_pipe;
|
|
||||||
|
|
||||||
typedef typename handle_type::executor_type executor_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marker struct for when we use the default Wine prefix.
|
* Marker struct for when we use the default Wine prefix.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
#include "../boost-fix.h"
|
#include "../boost-fix.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <boost/asio/read_until.hpp>
|
|
||||||
#include <boost/process/environment.hpp>
|
#include <boost/process/environment.hpp>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
@@ -101,8 +100,10 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path)
|
|||||||
// Write this process's original STDOUT and STDERR streams to the logger
|
// Write this process's original STDOUT and STDERR streams to the logger
|
||||||
// TODO: This works for output generated by plugins, but not for debug
|
// TODO: This works for output generated by plugins, but not for debug
|
||||||
// messages generated by wineserver. Is it possible to catch those?
|
// messages generated by wineserver. Is it possible to catch those?
|
||||||
async_log_pipe_lines(stdout_redirect.pipe, stdout_buffer, "[STDOUT] ");
|
logger.async_log_pipe_lines(stdout_redirect.pipe, stdout_buffer,
|
||||||
async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer, "[STDERR] ");
|
"[STDOUT] ");
|
||||||
|
logger.async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer,
|
||||||
|
"[STDERR] ");
|
||||||
|
|
||||||
stdio_handler = Win32Thread([&]() {
|
stdio_handler = Win32Thread([&]() {
|
||||||
// In case a plugin generates a lot of FIXMEs relaying this IO with
|
// In case a plugin generates a lot of FIXMEs relaying this IO with
|
||||||
@@ -300,27 +301,6 @@ void GroupBridge::async_handle_events() {
|
|||||||
[&]() { return !is_event_loop_inhibited(); });
|
[&]() { return !is_event_loop_inhibited(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupBridge::async_log_pipe_lines(
|
|
||||||
boost::asio::posix::stream_descriptor& pipe,
|
|
||||||
boost::asio::streambuf& buffer,
|
|
||||||
std::string prefix) {
|
|
||||||
boost::asio::async_read_until(
|
|
||||||
pipe, buffer, '\n',
|
|
||||||
[&, prefix](const boost::system::error_code& error, size_t) {
|
|
||||||
// When we get an error code then that likely means that the pipe
|
|
||||||
// has been clsoed and we have reached the end of the file
|
|
||||||
if (error.failed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string line;
|
|
||||||
std::getline(std::istream(&buffer), line);
|
|
||||||
logger.log(prefix + line);
|
|
||||||
|
|
||||||
async_log_pipe_lines(pipe, buffer, prefix);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::asio::local::stream_protocol::acceptor create_acceptor_if_inactive(
|
boost::asio::local::stream_protocol::acceptor create_acceptor_if_inactive(
|
||||||
boost::asio::io_context& io_context,
|
boost::asio::io_context& io_context,
|
||||||
boost::asio::local::stream_protocol::endpoint& endpoint) {
|
boost::asio::local::stream_protocol::endpoint& endpoint) {
|
||||||
|
|||||||
@@ -16,15 +16,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "../boost-fix.h"
|
#include "../boost-fix.h"
|
||||||
|
|
||||||
#include <boost/asio/local/stream_protocol.hpp>
|
#include <boost/asio/local/stream_protocol.hpp>
|
||||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
|
||||||
#include <boost/asio/streambuf.hpp>
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include "../common/logging/common.h"
|
#include "../common/logging/common.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
@@ -190,20 +187,6 @@ class GroupBridge {
|
|||||||
*/
|
*/
|
||||||
void async_handle_events();
|
void async_handle_events();
|
||||||
|
|
||||||
/**
|
|
||||||
* Continuously read from a pipe and write the output to the log file. Used
|
|
||||||
* with the IO streams captured by `stdout_redirect` and `stderr_redirect`.
|
|
||||||
*
|
|
||||||
* TODO: Merge this with `HostProcess::async_log_pipe_lines`
|
|
||||||
*
|
|
||||||
* @param pipe The pipe to read from.
|
|
||||||
* @param buffer The stream buffer to write to.
|
|
||||||
* @param prefix Text to prepend to the line before writing to the log.
|
|
||||||
*/
|
|
||||||
void async_log_pipe_lines(boost::asio::posix::stream_descriptor& pipe,
|
|
||||||
boost::asio::streambuf& buffer,
|
|
||||||
std::string prefix);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logging facility used for this group host process. Since we can't
|
* The logging facility used for this group host process. Since we can't
|
||||||
* identify which plugin is generating (debug) output, every line will only
|
* identify which plugin is generating (debug) output, every line will only
|
||||||
|
|||||||
Reference in New Issue
Block a user