Belle II Software  release-08-01-10
LogConnectionConsole Class Referencefinal

Implements a log connection to an IO Stream. More...

#include <LogConnectionConsole.h>

Inheritance diagram for LogConnectionConsole:
Collaboration diagram for LogConnectionConsole:

Public Member Functions

 LogConnectionConsole (int outputFD, bool color)
 Constructor. More...
 
 LogConnectionConsole (int outputFD)
 Constructor which automatically enables color if the file descriptor is a terminal and supports colors. More...
 
 ~LogConnectionConsole () override
 Destructor.
 
bool sendMessage (const LogMessage &message) override
 Sends a log message. More...
 
void write (const std::string &message)
 Send a preformatted string message to the connected output.
 
bool isConnected () override
 Returns true if the connection to the io stream could be established.
 
void finalizeOnAbort () override
 Make sure output is flushed on abort.
 

Static Public Member Functions

static bool terminalSupportsColors (int fileDescriptor)
 Returns true if the given file descriptor is a tty and supports colors.
 
static bool getPythonLoggingEnabled ()
 Check whether console logging via python is enabled.
 
static void setPythonLoggingEnabled (bool enabled)
 Set whether console logging via pyhthon is enabled.
 
static bool getEscapeNewlinesEnabled ()
 Check whether we want to escape newlines on console.
 
static void setEscapeNewlinesEnabled (bool enabled)
 Set whether we want to escape newlines on console.
 

Private Attributes

int m_fd
 The output stream used for sending the log message.
 
bool m_color
 Flag for color output.
 

Static Private Attributes

static bool s_pythonLoggingEnabled {false}
 Flag to indicate whether log messages should be sent to python sys.stdout.
 
static bool s_escapeNewlinesEnabled {false}
 Flag to indicate whether newlines should be replaced by '
' in the output.
 

Detailed Description

Implements a log connection to an IO Stream.

Inherits from the abstract base class LogConnectionBase.

Definition at line 24 of file LogConnectionConsole.h.

Constructor & Destructor Documentation

◆ LogConnectionConsole() [1/2]

LogConnectionConsole ( int  outputFD,
bool  color 
)

Constructor.

Parameters
outputFDThe output file descriptor to write to
colorwhether color should be used for output

Definition at line 23 of file LogConnectionConsole.cc.

23  :
24  m_fd(dup(outputFD)), m_color(color)
25 {
26  // check fd
27  if (m_fd < 0) throw std::runtime_error(std::string("Error duplicating file descriptor: ") + std::strerror(errno));
28 }
bool m_color
Flag for color output.
int m_fd
The output stream used for sending the log message.

◆ LogConnectionConsole() [2/2]

LogConnectionConsole ( int  outputFD)
inlineexplicit

Constructor which automatically enables color if the file descriptor is a terminal and supports colors.

Parameters
outputFDThe output file descriptor to write to.

Definition at line 35 of file LogConnectionConsole.h.

35 : LogConnectionConsole(outputFD, terminalSupportsColors(outputFD)) {}
LogConnectionConsole(int outputFD, bool color)
Constructor.
static bool terminalSupportsColors(int fileDescriptor)
Returns true if the given file descriptor is a tty and supports colors.

Member Function Documentation

◆ sendMessage()

bool sendMessage ( const LogMessage message)
overridevirtual

Sends a log message.

Parameters
messageThe log message object.
Returns
true if the message could be send.

Implements LogConnectionBase.

Definition at line 64 of file LogConnectionConsole.cc.


The documentation for this class was generated from the following files: