52 #ifndef LOGGER_EXTERNALERRORHANDLER_HPP
53 #define LOGGER_EXTERNALERRORHANDLER_HPP
58 #include <string_view>
105 PosixId fileDescriptorsArray[2];
116 {
return fileDescriptorsArray[0]; }
122 {
return fileDescriptorsArray[1]; }
132 bool setDescriptorInheritanceMode(
bool inherit );
141 bool redirectWriteEnd(
int targetFd );
150 static constexpr
PosixId m_disabledPipeEnd = -1;
153 static constexpr
PosixId m_errorResult = -1;
159 PosixId m_originalStreamTarget;
162 Pipe m_deviationPipe;
175 static bool setPipeEndBlockingMode(
PosixId pipeEnd,
bool nonBlocking );
183 static int duplicateDescriptor(
int pipeEnd );
190 void prepareStreamingBuffer();
196 static void closePipeEnd(
PosixId & pipeEnd );
202 static string getLastPosixErrorString();
240 { m_processErrorFunctor = errorHandlingFunctor; }
267 std::unique_ptr< OutputStreamDeviation > m_stderrDeviation;
This file provides the infrastructure to capture external errors.
Class to handle external error capture. This class role is to capture and process external error mess...
~ExternalErrorHandler()
Destructor, disable all error piping features.
void setErrorHandling(ErrorHandlingFunctor &&errorHandlingFunctor)
Set the function that process the external errors that have been captured. The processing typically c...
void flush(std::string_view detectionLocation)
Process all awaiting captured errors that were produced externally, then clear the error stream.
void enableStderrPipeDeviation(bool enable)
Enable capture of errors piped from the std::cerr stream. Helpful to capture GLIBC errors,...
static ExternalErrorHandler & instance()
Strinct singleton pattern has been choosen since we will only have single sources of external errors ...
static void defaultErrorHandling(std::string_view errorMsg, std::string_view detectionLocation)
Not designed for direct calls, error handling function in default use if never calling setErrorHandli...
OutputStreamDeviation::LineHandlingFunctor ErrorHandlingFunctor
A functor executed for each error mesage to process, taking the message as the 1st string_view parame...
This class implements pipe redirection to allow to capture and process externally streamed messages.
std::function< void(std::string_view, std::string_view) > LineHandlingFunctor
A functor executed for each independant lines to process, taking the line as the 1st string_view para...
OutputStreamDeviation(PosixId fileNo)
Construct and enable a new pipe redirection.
void flush(LineHandlingFunctor const &lineProcessingFunctor, std::string_view detectionLocation)
Flush the buffer from the original output pipe in a string, allowing to log it where needed.
~OutputStreamDeviation()
Destroy the OutputStreamDeviation object, restoring the original pipe state.
int PosixId
Posix identifier, can be a file handle, an error number... Must be consistent with posix functions.
std::string string
String type.
std::string_view string_view
String type.