E-MailRelay
|
Controls and implements low-level logging output, as used by G::Log. More...
#include <glogoutput.h>
Classes | |
struct | Config |
A configuration structure for G::LogOutput. More... | |
Public Types | |
enum class | SyslogFacility { User , Daemon , Mail , Cron , Local0 , Local1 , Local2 , Local3 , Local4 , Local5 , Local6 , Local7 } |
Public Member Functions | |
LogOutput (const std::string &exename, const Config &config, const std::string &filename=std::string()) | |
Constructor. More... | |
LogOutput (bool output_enabled_and_summary_info, bool verbose_info_and_debug=true, const std::string &filename=std::string()) | |
Constructor for test programs. More... | |
~LogOutput () | |
Destructor. More... | |
Config | config () const |
Returns the current configuration. More... | |
void | configure (const Config &) |
Updates the current configuration. More... | |
bool | at (Log::Severity) const noexcept |
Returns true if logging should occur for the given severity level. More... | |
LogOutput (const LogOutput &)=delete | |
LogOutput (LogOutput &&)=delete | |
void | operator= (const LogOutput &)=delete |
void | operator= (LogOutput &&)=delete |
Static Public Member Functions | |
static LogOutput * | instance () noexcept |
Returns a pointer to the controlling LogOutput object. More... | |
static void | context (std::string(*fn)(void *)=nullptr, void *fn_arg=nullptr) noexcept |
Sets a functor that is used to provide a context string for every log line, if configured. More... | |
static void * | contextarg () noexcept |
Returns the functor argument as set by the last call to context(). More... | |
static std::ostream & | start (Log::Severity, const char *file, int line) |
Prepares the internal ostream for a new log line and returns a reference to it. More... | |
static void | output (std::ostream &) |
Emits the current log line (see start()). More... | |
static void | assertion (const char *file, int line, bool test, const char *test_string) |
Performs an assertion check. More... | |
static void | assertion (const char *file, int line, void *test, const char *test_string) |
Performs an assertion check. More... | |
static void | assertionFailure (const char *file, int line, const char *test_expression) noexcept |
Reports an assertion failure. More... | |
static void | assertionAbort () GDEF_NORETURN |
Aborts the program when an assertion has failed. More... | |
static void | register_ (const std::string &exe) |
Registers the given executable as a source of logging. More... | |
static void | translate (const std::string &info, const std::string &warning, const std::string &error, const std::string &fatal) |
Sets the prefix string for the various log levels (including trailing punctuation). More... | |
Controls and implements low-level logging output, as used by G::Log.
Applications should instantiate a LogOutput object in main() to enable and configure log output.
The implementation uses a file descriptor for osoutput() rather than a stream because windows file-sharing options are not accessible when building with mingw streams, and to avoid double buffering.
Definition at line 49 of file glogoutput.h.
|
strong |
Definition at line 52 of file glogoutput.h.
G::LogOutput::LogOutput | ( | const std::string & | exename, |
const Config & | config, | ||
const std::string & | filename = std::string() |
||
) |
Constructor.
If there is no LogOutput object, or if 'config.output_enabled' is false, then there is no output of any sort (except for assertions to stderr). Otherwise at least warning and error messages are generated.
If 'config.summary_info' is true then log-summary messages are output. If 'config.verbose_info' is true then log-verbose messages are output. If 'config.with_debug' is true then debug messages will also be generated (but only if compiled in).
If an output filename is given it has a "%d" substitution applied and it is then opened or created before this constructor returns. If no filename is given then logging is sent to the standard error stream; the user is free to close stderr and reopen it onto /dev/null if only syslog logging is required.
More than one LogOutput object may be created, but only the first one controls output.
Definition at line 77 of file glogoutput.cpp.
|
explicit |
Constructor for test programs.
Only generates output if the first parameter is true. Never uses syslog.
Definition at line 91 of file glogoutput.cpp.
G::LogOutput::~LogOutput | ( | ) |
Destructor.
Definition at line 119 of file glogoutput.cpp.
|
inlinestatic |
Performs an assertion check.
Definition at line 221 of file glogoutput.h.
|
inlinestatic |
Performs an assertion check.
This overload, using a test on a pointer, is motivated by MSVC warnings.
Definition at line 230 of file glogoutput.h.
|
static |
Aborts the program when an assertion has failed.
Definition at line 289 of file glogoutput.cpp.
|
staticnoexcept |
Reports an assertion failure.
Definition at line 272 of file glogoutput.cpp.
|
noexcept |
Returns true if logging should occur for the given severity level.
Returns false if there is no LogOutput instance.
Definition at line 149 of file glogoutput.cpp.
G::LogOutput::Config G::LogOutput::config | ( | ) | const |
Returns the current configuration.
Definition at line 109 of file glogoutput.cpp.
void G::LogOutput::configure | ( | const Config & | config | ) |
Updates the current configuration.
Definition at line 114 of file glogoutput.cpp.
|
staticnoexcept |
Sets a functor that is used to provide a context string for every log line, if configured.
The functor should return the context string with trailing punctuation, typically colon and space.
Definition at line 133 of file glogoutput.cpp.
|
staticnoexcept |
Returns the functor argument as set by the last call to context().
Definition at line 143 of file glogoutput.cpp.
|
staticnoexcept |
Returns a pointer to the controlling LogOutput object.
Returns nullptr if none.
Definition at line 128 of file glogoutput.cpp.
|
static |
Emits the current log line (see start()).
Does nothing if there is no LogOutput instance.
Definition at line 169 of file glogoutput.cpp.
|
static |
Registers the given executable as a source of logging.
This is called from osinit(), but it might also need to be done as a program installation step with the necessary process permissions.
Definition at line 91 of file glogoutput_unix.cpp.
|
static |
Prepares the internal ostream for a new log line and returns a reference to it.
The caller should stream out the rest of the log line into the ostream and then call output(). Calls to start() and output() must be strictly in pairs. Returns a pointer to a dummy ostream if there is no LogOutput instance.
Definition at line 161 of file glogoutput.cpp.
|
static |
Sets the prefix string for the various log levels (including trailing punctuation).
Definition at line 341 of file glogoutput.cpp.