E-MailRelay
Public Types | Public Member Functions | Static Public Member Functions | List of all members
G::LogOutput Class Reference

Controls and implements low-level logging output, as used by the Log interface. More...

#include <glogoutput.h>

Public Types

enum  SyslogFacility { User, Daemon, Mail, Cron }
 

Public Member Functions

 LogOutput (const std::string &prefix, bool output, bool summary_logging, bool verbose_logging, bool with_debug, bool with_level, bool with_timestamp, bool strip_context, bool use_syslog, const std::string &stderr_replacement=std::string(), SyslogFacility syslog_facility=User)
 Constructor. More...
 
 LogOutput (bool output_with_logging, bool verbose_and_debug=true, const std::string &stderr_replacement=std::string())
 Constructor for test programs. More...
 
virtual ~LogOutput ()
 Destructor.
 
virtual void rawOutput (std::ostream &, G::Log::Severity, const std::string &)
 Overridable. More...
 
bool enable (bool enabled=true)
 Enables or disables output. Returns the previous setting.
 
void quiet (bool quiet_stderr=true)
 Enables or disables quiet-stderr mode, intended for daemons that log to syslog and only want startup errors and warnings on stderr. More...
 
void verbose (bool verbose_log=true)
 Enables or disables verbose logging.
 
bool at (G::Log::Severity) const
 Returns true if logging should occur for the given severity level.
 
bool at (G::Log::Severity, const std::string &group) const
 Returns true if logging should occur for the given severity level and logging group. More...
 
bool syslog () const
 Returns true if syslog output is enabled.
 
virtual void onAssert ()
 Called during an assertion failure. More...
 

Static Public Member Functions

static LogOutput * instance ()
 Returns a pointer to the controlling LogOutput object. More...
 
static void groups (const std::string &)
 Sets the list of active logging groups. More...
 
static void output (G::Log::Severity, const char *file, int line, const std::string &)
 Generates output if there is an existing LogOutput object which is enabled. More...
 
static void assertion (const char *file, int line, bool test, const char *)
 Makes an assertion check (regardless of any LogOutput object). More...
 
static void register_ (const std::string &exe)
 Registers the given executable as a source of logging. More...
 

Detailed Description

Controls and implements low-level logging output, as used by the Log interface.

Applications should instantiate a LogOutput object in main() to enable log output.

See also
G::Log

Definition at line 42 of file glogoutput.h.

Constructor & Destructor Documentation

G::LogOutput::LogOutput ( const std::string &  prefix,
bool  output,
bool  summary_logging,
bool  verbose_logging,
bool  with_debug,
bool  with_level,
bool  with_timestamp,
bool  strip_context,
bool  use_syslog,
const std::string &  stderr_replacement = std::string(),
SyslogFacility  syslog_facility = User 
)

Constructor.

If there is no LogOutput object, or if 'output' is false, then there is no output of any sort. Otherwise at least warning and error messages are generated.

If 'summary_logging' is true then log-summary messages are output. If 'verbose_logging' is true then log-verbose messages are output. If 'with_debug' is true then debug messages will also be generated (but only if compiled in).

More than one LogOutput object may be created, but only the first one controls output.

Definition at line 34 of file glogoutput.cpp.

G::LogOutput::LogOutput ( bool  output_with_logging,
bool  verbose_and_debug = true,
const std::string &  stderr_replacement = std::string() 
)
explicit

Constructor for test programs.

Only generates output if the first parameter is true. Never uses syslog.

Definition at line 59 of file glogoutput.cpp.

Member Function Documentation

void G::LogOutput::assertion ( const char *  file,
int  line,
bool  test,
const char *  test_string 
)
static

Makes an assertion check (regardless of any LogOutput object).

Calls output() if the 'file' parameter is not null.

Definition at line 283 of file glogoutput.cpp.

bool G::LogOutput::at ( G::Log::Severity  severity,
const std::string &  group 
) const

Returns true if logging should occur for the given severity level and logging group.

Definition at line 170 of file glogoutput.cpp.

void G::LogOutput::groups ( const std::string &  list)
static

Sets the list of active logging groups.

The string is a comma-separated list of "log-whatever" names, with "log-all" having the obvious meaning. Names that do not start with "log-" are ignored. The default set of groups is taken from an environment variable on construction. Does nothing if there is no instance().

Definition at line 154 of file glogoutput.cpp.

G::LogOutput * G::LogOutput::instance ( )
static

Returns a pointer to the controlling LogOutput object.

Returns nullptr if none.

Definition at line 114 of file glogoutput.cpp.

void G::LogOutput::onAssert ( )
virtual

Called during an assertion failure.

This allows Windows applications to stop timers etc. (Timers can cause reentrancy problems and infinitely recursive dialog box creation.)

Definition at line 227 of file glogoutput.cpp.

void G::LogOutput::output ( G::Log::Severity  severity,
const char *  file,
int  line,
const std::string &  text 
)
static

Generates output if there is an existing LogOutput object which is enabled.

Uses rawOutput().

Definition at line 136 of file glogoutput.cpp.

void G::LogOutput::quiet ( bool  quiet_stderr = true)

Enables or disables quiet-stderr mode, intended for daemons that log to syslog and only want startup errors and warnings on stderr.

Definition at line 126 of file glogoutput.cpp.

void G::LogOutput::rawOutput ( std::ostream &  std_err,
G::Log::Severity  severity,
const std::string &  message 
)
virtual

Overridable.

Used to do the final message output (with OutputDebugString() or stderr).

Definition at line 51 of file glogoutput_unix.cpp.

void G::LogOutput::register_ ( const std::string &  exe)
static

Registers the given executable as a source of logging.

This is called from init(), but it might also need to be done as an installation task with the necessary permissions.

Definition at line 70 of file glogoutput_unix.cpp.


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