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 char* term = getenv(
"TERM");
45 const std::string termName = term ? term :
"";
46 const bool useColor = isTTY and
47 (termName ==
"xterm" or termName ==
"xterm-color" or termName ==
"xterm-256color" or
48 termName ==
"sceen" or termName ==
"screen-256color" or termName ==
"tmux" or
49 termName ==
"tmux-256color" or termName ==
"rxvt-unicode" or
50 termName ==
"rxvt-unicode-256color" or termName ==
"linux" or termName ==
"cygwin");
57 auto pymessage = boost::python::import(
"sys").attr(
"stdout");
58 pymessage.attr(
"write")(message);
59 pymessage.attr(
"flush")();
69 std::stringstream stream;
71 const std::string color_str[] = {
79 const std::string& c{color_str[message.getLogLevel()]};
83 std::string messagestr = stream.str();
86 boost::trim_right_if(messagestr, boost::is_any_of(
" \t\n\r"));
88 boost::replace_all(messagestr,
"\n",
"\\n");
93 messagestr +=
"\x1b[m";
104 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.