57 G_EXCEPTION( LogFileError ,
tx(
"cannot open log file") ) ;
58 G_EXCEPTION( EventLogError ,
tx(
"cannot access the system event log") ) ;
60 enum class SyslogFacility
78 bool m_output_enabled {
false} ;
79 bool m_summary_info {
false} ;
80 bool m_verbose_info {
false} ;
81 bool m_more_verbose_info {
false} ;
82 bool m_debug {
false} ;
83 bool m_with_level {
false} ;
84 bool m_with_timestamp {
false} ;
85 bool m_with_context {
false} ;
86 bool m_strip {
false} ;
87 bool m_quiet_stderr {
false} ;
88 bool m_use_syslog {
false} ;
89 bool m_allow_bad_syslog {
false} ;
90 bool m_stdout {
false} ;
91 SyslogFacility m_facility {SyslogFacility::User} ;
92 Process::Umask::Mode m_umask {Process::Umask::Mode::NoChange} ;
94 Config & set_output_enabled(
bool value =
true ) ;
95 Config & set_summary_info(
bool value =
true ) ;
96 Config & set_verbose_info(
bool value =
true ) ;
97 Config & set_more_verbose_info(
bool value =
true ) ;
98 Config & set_debug(
bool value =
true ) ;
99 Config & set_with_level(
bool value =
true ) ;
100 Config & set_with_timestamp(
bool value =
true ) ;
101 Config & set_with_context(
bool value =
true ) ;
102 Config & set_strip(
bool value =
true ) ;
103 Config & set_quiet_stderr(
bool value =
true ) ;
104 Config & set_use_syslog(
bool value =
true ) ;
105 Config & set_allow_bad_syslog(
bool value =
true ) ;
106 Config & set_facility( SyslogFacility ) ;
107 Config & set_umask( Process::Umask::Mode ) ;
108 Config & set_stdout(
bool value =
true ) ;
112 const std::string & filename = {} ) ;
135 explicit LogOutput(
bool output_enabled_and_summary_info ,
136 bool verbose_info_and_debug =
true ,
137 const std::string & filename = {} ) ;
154 bool at( Log::Severity ) const noexcept ;
157 static
void context(
std::
string (*fn)(
void*) =
nullptr ,
void * fn_arg =
nullptr ) noexcept ;
166 static LogStream &
start( Log::Severity , const
char * file ,
int line ) noexcept ;
173 static
void output( LogStream & ) noexcept ;
177 static
void assertion( const
char * file ,
int line ,
bool test , const
char * test_string ) ;
180 static
void assertion( const
char * file ,
int line ,
void * test , const
char * test_string ) ;
184 static
void assertionFailure( const
char * file ,
int line , const
char * test_expression ) noexcept ;
187 GDEF_NORETURN_LHS static
void assertionAbort() GDEF_NORETURN_RHS ;
204 void open( const
std::
string & ,
bool ) ;
205 LogStream &
start( Log::Severity ) ;
206 void output( LogStream & ,
int ) ;
207 void osoutput(
int , Log::Severity ,
char * ,
std::
size_t ) ;
208 void oscleanup() const noexcept ;
210 bool updatePath( const
std::
string & ,
std::
string & ) const ;
211 std::
string makePath( const
std::
string & ) const ;
212 void appendTimeTo( LogStream & ) ;
213 static
G::string_view levelString( Log::Severity ) noexcept ;
214 static const
char * basename( const
char * ) noexcept ;
217 std::
string m_exename ;
219 std::time_t m_time_s{0} ;
220 unsigned int m_time_us{0U} ;
221 std::array<char,17U> m_time_buffer {} ;
222 std::array<char,17U> m_time_change_buffer {} ;
225 std::string m_real_path ;
227 unsigned int m_depth{0U} ;
228 Log::Severity m_severity{Log::Severity::Debug} ;
229 std::size_t m_start_pos{0U} ;
230 std::string (*m_context_fn)(
void *){
nullptr} ;
231 void * m_context_fn_arg{
nullptr} ;
247 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 GDEF_NORETURN_LHS void assertionAbort() GDEF_NORETURN_RHS
Aborts the program when an assertion has failed.
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 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.
Config config() const
Returns the current configuration.
static void * contextarg() noexcept
Returns the functor argument as set by the last call to context().
static void output(LogStream &) noexcept
Emits the current log line (see start()).
LogOutput(const std::string &exename, const Config &config, const std::string &filename={})
Constructor.
void configure(const Config &)
Updates the current configuration.
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.
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().
A configuration structure for G::LogOutput.