Belle II Software development
LogConnectionConsole.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/logging/LogConnectionBase.h>
12#include <string>
13
14namespace Belle2 {
25 public:
30 LogConnectionConsole(int outputFD, bool color);
31
35 explicit LogConnectionConsole(int outputFD): LogConnectionConsole(outputFD, terminalSupportsColors(outputFD)) {}
36
38 static bool terminalSupportsColors(int fileDescriptor);
39
41 ~LogConnectionConsole() override;
42
47 bool sendMessage(const LogMessage& message) override;
48
50 void write(const std::string& message);
51
53 bool isConnected() override;
54
58 static void setPythonLoggingEnabled(bool enabled) { s_pythonLoggingEnabled = enabled; }
62 static void setEscapeNewlinesEnabled(bool enabled) { s_escapeNewlinesEnabled = enabled; }
64 void finalizeOnAbort() override;
65 private:
66 int m_fd;
67 bool m_color;
70 };
71
73} // end namespace Belle2
Abstract base class for the different types of log connections.
Implements a log connection to an IO Stream.
static bool getEscapeNewlinesEnabled()
Check whether we want to escape newlines on console.
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.
static void setEscapeNewlinesEnabled(bool enabled)
Set whether we want to escape newlines on console.
static void setPythonLoggingEnabled(bool enabled)
Set whether console logging via pyhthon is enabled.
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.
LogConnectionConsole(int outputFD)
Constructor which automatically enables color if the file descriptor is a terminal and supports color...
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.
The LogMessage class.
Definition: LogMessage.h:29
Abstract base class for different kinds of events.