52 enum class SyslogFacility {
68 bool m_output_enabled{
false} ;
69 bool m_summary_info{
false} ;
70 bool m_verbose_info{
false} ;
72 bool m_with_level{
false} ;
73 bool m_with_timestamp{
false} ;
74 bool m_with_context{
false} ;
76 bool m_quiet_stderr{
false} ;
77 bool m_use_syslog{
false} ;
78 bool m_allow_bad_syslog{
false} ;
79 SyslogFacility m_facility{SyslogFacility::User} ;
81 Config & set_output_enabled(
bool value =
true ) ;
82 Config & set_summary_info(
bool value =
true ) ;
83 Config & set_verbose_info(
bool value =
true ) ;
84 Config & set_debug(
bool value =
true ) ;
85 Config & set_with_level(
bool value =
true ) ;
86 Config & set_with_timestamp(
bool value =
true ) ;
87 Config & set_with_context(
bool value =
true ) ;
88 Config & set_strip(
bool value =
true ) ;
89 Config & set_quiet_stderr(
bool value =
true ) ;
90 Config & set_use_syslog(
bool value =
true ) ;
91 Config & set_allow_bad_syslog(
bool value =
true ) ;
92 Config & set_facility( SyslogFacility ) ;
96 const std::string & filename = std::string() ) ;
119 explicit LogOutput(
bool output_enabled_and_summary_info ,
120 bool verbose_info_and_debug =
true ,
121 const std::string & filename = std::string() ) ;
138 bool at(
Log::Severity ) const noexcept ;
142 static
void context( std::
string (*fn)(
void*) =
nullptr ,
void * fn_arg =
nullptr ) noexcept ;
151 static std::ostream &
start(
Log::Severity , const
char * file ,
int line ) ;
158 static
void output( std::ostream & ) ;
162 static
void assertion( const
char * file ,
int line ,
bool test , const
char * test_string ) ;
165 static
void assertion( const
char * file ,
int line ,
void * test , const
char * test_string ) ;
169 static
void assertionFailure( const
char * file ,
int line , const
char * test_expression ) noexcept ;
175 static
void register_( const std::
string & exe ) ;
181 static
void translate( const std::
string & info , const std::
string & warning ,
182 const std::
string & error , const std::
string & fatal ) ;
189 void operator=( const
LogOutput & ) = delete ;
190 void operator=(
LogOutput && ) = delete ;
194 void open( std::
string ,
bool ) ;
195 std::ostream &
start(
Log::Severity ) ;
196 void output( std::ostream & ,
int ) ;
197 void osoutput(
int ,
Log::Severity ,
char * , std::
size_t ) ;
198 void oscleanup() const noexcept ;
200 void appendTimeTo( std::ostream & ) ;
201 static const
char * levelString(
Log::Severity ) noexcept ;
202 static const
char * basename( const
char * ) noexcept ;
205 std::
string m_exename ;
207 std::time_t m_time_s{0} ;
208 unsigned int m_time_us{0U} ;
209 std::vector<char> m_time_buffer ;
210 std::array<char,8U> m_date_buffer {} ;
214 unsigned int m_depth{1U} ;
215 Log::Severity m_severity{Log::Severity::s_Debug} ;
216 std::size_t m_start_pos{0U} ;
217 std::string (*m_context_fn)(
void *){
nullptr} ;
218 void * m_context_fn_arg{
nullptr} ;
234 assertionFailure( file , line , test_string ) ;
A static interface for daemonising the calling process.
Controls and implements low-level logging output, as used by G::Log.
static void assertion(const char *file, int line, bool test, const char *test_string)
Performs an assertion check.
static void register_(const std::string &exe)
Registers the given executable as a source of logging.
bool at(Log::Severity) const noexcept
Returns true if logging should occur for the given severity level.
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).
Config config() const
Returns the current configuration.
static void output(std::ostream &)
Emits the current log line (see start()).
static void * contextarg() noexcept
Returns the functor argument as set by the last call to context().
LogOutput(const std::string &exename, const Config &config, const std::string &filename=std::string())
Constructor.
void configure(const Config &)
Updates the current configuration.
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.
static void assertionFailure(const char *file, int line, const char *test_expression) noexcept
Reports an assertion failure.
static LogOutput * instance() noexcept
Returns a pointer to the controlling LogOutput object.
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.
static void assertionAbort() GDEF_NORETURN
Aborts the program when an assertion has failed.
A class for doing iostream-based logging.
A configuration structure for G::LogOutput.