cppthread 1.1.16
C++ Thread Library
Classes | Typedefs | Enumerations | Functions
log.h File Reference

Declaration of the log class used to send error messages. More...

#include <cstdint>
#include <iostream>
#include <sstream>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cppthread::logger
 The cppthread logger. More...
 

Typedefs

typedef void(* cppthread::log_callback) (log_level_t level, std::string const &message)
 The log callback type definition.
 

Enumerations

enum class  cppthread::log_level_t {
  debug , info , warning , error ,
  fatal , LOG_LEVEL_SIZE
}
 The log level or severity. More...
 

Functions

loggercppthread::end (logger &l)
 Close a log statement.
 
void cppthread::set_log_callback (log_callback callback)
 Set a callback function.
 
std::string cppthread::to_string (log_level_t level)
 Convert a log level to a string.
 

Detailed Description

The library offers a log facility for when messages are generated on errors and various output (i.e. –help).

Definition in file log.h.

Typedef Documentation

◆ log_callback

cppthread::log_callback

By default, log messages will be sent to your console using std::cerr. By setting up a log_callback function instead, it will be sent to your function.

Parameters
[in]levelThe level (severity) of this log message.
[in]messageThe message to be logged.

Definition at line 53 of file log.h.

Enumeration Type Documentation

◆ log_level_t

enum class cppthread::log_level_t
strong

How important/severe the log message is.

Warning
Note that logging a message with level fatal does not stop your program. It's just a log level. You are responsible for stopping your program if the error is indeed fatal.

Definition at line 39 of file log.h.

Function Documentation

◆ end()

cppthread::end ( logger l)
inline

This function is used to simplified the end of a log statement:

int err(errno);
log << cppthread::log_level_t::fatal
<< "the initialization failed with errno = "
<< err
<< cppthread::end;

The result is a call to the logger::end() function which sends the message to the logger current output.

Parameters
[in]lA reference to the logger.
Returns
A reference to the logger.

Definition at line 90 of file log.h.

References cppthread::logger::end(), and cppthread::end().

Referenced by cppthread::mutex::mutex(), cppthread::guard::~guard(), cppthread::mutex::~mutex(), cppthread::runner::~runner(), cppthread::thread::~thread(), cppthread::mutex::broadcast(), cppthread::mutex::dated_wait(), cppthread::deswappify(), cppthread::end(), cppthread::runner::enter(), cppthread::thread::init(), cppthread::thread::internal_enter(), cppthread::thread::internal_leave(), cppthread::thread::internal_run(), cppthread::thread::internal_thread(), cppthread::runner::leave(), cppthread::mutex::lock(), cppthread::mutex::safe_broadcast(), cppthread::mutex::safe_signal(), cppthread::mutex::signal(), cppthread::thread::start(), cppthread::mutex::timed_wait(), cppthread::mutex::try_lock(), cppthread::mutex::unlock(), and cppthread::mutex::wait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_log_callback()

void cppthread::set_log_callback ( log_callback  callback)

Set a callback function used to redirect the logs generated by the cppthread library and any library that makes use of this log facility (i.e. the advgetopt project does so).

Note
You should not use this facility unless you do not have access to the snaplogger, somehow. The snaplogger is a much more advanced and better interface especially in a multithreaded application.
Parameters
[in]callbackThe function to call whenever a log is generated.

Definition at line 170 of file log.cpp.

References cppthread::set_log_callback().

Referenced by cppthread::set_log_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_string()

std::string cppthread::to_string ( log_level_t  level)

This function transforms a log_level_t value to a string which can then be used in a log message.

Exceptions
cppthread_invalid_errorIf the log level is not one of the know log levels, then the function raises this exception.
Parameters
[in]levelThe message log level to convert to a string.
Returns
A string representing the log level.

Definition at line 610 of file log.cpp.

References cppthread::to_string().

Referenced by cppthread::pool< W, A >::worker_thread_t::worker_thread_t(), cppthread::logger::end(), and cppthread::to_string().

Here is the call graph for this function:
Here is the caller graph for this function:

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.