9#include <framework/logging/LogConnectionConsole.h>
10#include <framework/logging/LogMessage.h>
11#include <boost/python.hpp>
12#include <boost/algorithm/string.hpp>
24 m_fd(dup(outputFD)), m_color(color)
27 if (
m_fd < 0)
throw std::runtime_error(std::string(
"Error duplicating file descriptor: ") + std::strerror(errno));
43 const bool isTTY = isatty(fileDescriptor);
44 const std::string termName = getenv(
"TERM") ? getenv(
"TERM") :
"";
45 const bool useColor = isTTY and
46 (termName ==
"xterm" or termName ==
"xterm-color" or termName ==
"xterm-256color" or
47 termName ==
"sceen" or termName ==
"screen-256color" or termName ==
"tmux" or
48 termName ==
"tmux-256color" or termName ==
"rxvt-unicode" or
49 termName ==
"rxvt-unicode-256color" or termName ==
"linux" or termName ==
"cygwin");
56 auto pymessage = boost::python::import(
"sys").attr(
"stdout");
57 pymessage.attr(
"write")(message);
58 pymessage.attr(
"flush")();
68 std::stringstream stream;
70 const std::string color_str[] = {
78 const std::string& c{color_str[message.getLogLevel()]};
82 std::string messagestr = stream.str();
85 boost::trim_right_if(messagestr, boost::is_any_of(
" \t\n\r"));
87 boost::replace_all(messagestr,
"\n",
"\\n");
92 messagestr +=
"\x1b[m";
103 boost::python::import(
"sys").attr(
"stdout").attr(
"flush")();
bool m_color
Flag for color output.
static bool getPythonLoggingEnabled()
Check whether console logging via python is enabled.
static bool s_escapeNewlinesEnabled
Flag to indicate whether newlines should be replaced by ' ' in the output.
~LogConnectionConsole() override
Destructor.
LogConnectionConsole(int outputFD, bool color)
Constructor.
static bool terminalSupportsColors(int fileDescriptor)
Returns true if the given file descriptor is a tty and supports colors.
static bool s_pythonLoggingEnabled
Flag to indicate whether log messages should be sent to python sys.stdout.
bool isConnected() override
Returns true if the connection to the io stream could be established.
bool sendMessage(const LogMessage &message) override
Sends a log message.
int m_fd
The output stream used for sending the log message.
void finalizeOnAbort() override
Make sure output is flushed on abort.
void write(const std::string &message)
Send a preformatted string message to the connected output.
Abstract base class for different kinds of events.