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={}) | |
Constructor. More... | |
LogOutput (bool output_enabled_and_summary_info, bool verbose_info_and_debug=true, const std::string &filename={}) | |
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 | |
LogOutput & | operator= (const LogOutput &)=delete |
LogOutput & | 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 LogStream & | start (Log::Severity, const char *file, int line) noexcept |
Prepares the internal ostream for a new log line and returns a reference to it. More... | |
static void | output (LogStream &) noexcept |
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 GDEF_NORETURN_LHS void | assertionAbort () GDEF_NORETURN_RHS |
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... | |
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 54 of file glogoutput.h.
|
strong |
Definition at line 60 of file glogoutput.h.
G::LogOutput::LogOutput | ( | const std::string & | exename, |
const Config & | config, | ||
const std::string & | filename = {} |
||
) |
Constructor.
If there is no LogOutput object, or if 'config.output_enabled' is false, then there is no output at all except for assertions to stderr in a debug build. 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 "%d" and "%h" substitutions 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 98 of file glogoutput.cpp.
|
explicit |
Constructor for test programs.
Only generates output if the first parameter is true. Never uses syslog.
Definition at line 113 of file glogoutput.cpp.
G::LogOutput::~LogOutput | ( | ) |
Destructor.
Definition at line 143 of file glogoutput.cpp.
|
inlinestatic |
Performs an assertion check.
Definition at line 234 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 243 of file glogoutput.h.
|
static |
Aborts the program when an assertion has failed.
Definition at line 365 of file glogoutput.cpp.
|
staticnoexcept |
Reports an assertion failure.
Definition at line 348 of file glogoutput.cpp.
|
noexcept |
Returns true if logging should occur for the given severity level.
Definition at line 179 of file glogoutput.cpp.
G::LogOutput::Config G::LogOutput::config | ( | ) | const |
Returns the current configuration.
Definition at line 133 of file glogoutput.cpp.
void G::LogOutput::configure | ( | const Config & | config | ) |
Updates the current configuration.
Definition at line 138 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 163 of file glogoutput.cpp.
|
staticnoexcept |
Returns the functor argument as set by the last call to context().
Definition at line 173 of file glogoutput.cpp.
|
staticnoexcept |
Returns a pointer to the controlling LogOutput object.
Returns nullptr if none.
Definition at line 158 of file glogoutput.cpp.
|
staticnoexcept |
Emits the current log line (see start()).
Does nothing if there is no LogOutput instance.
Definition at line 208 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 92 of file glogoutput_unix.cpp.
|
staticnoexcept |
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 193 of file glogoutput.cpp.