SEVN
Loading...
Searching...
No Matches
sevnstd::SevnLogging Class Reference

#include <sevnlog.h>

Public Member Functions

 SevnLogging ()
 
 SevnLogging (int level)
 
 ~SevnLogging ()
 
void log (int level, std::string errstate, const char *file_input=nullptr, int line_input=-1, int stop=0) const
 
void debug (std::string errstate, const char *file_input=nullptr, int line_input=-1) const
 
void info (std::string errstate, const char *file_input=nullptr, int line_input=-1) const
 
void warning (std::string errstate, const char *file_input=nullptr, int line_input=-1) const
 
void error (std::string errstate, const char *file_input=nullptr, int line_input=-1, bool stop=true) const
 
template<class E >
void error (std::string errstate, const char *file_input=nullptr, int line_input=-1, bool stop=true, E &&err=nullptr) const
 
void critical (std::string errstate, const char *file_input=nullptr, int line_input=-1) const
 
template<class E >
void critical (std::string errstate, const char *file_input=nullptr, int line_input=-1, E &&err=nullptr) const
 
void pdebug () const
 Variadic prints. More...
 
template<typename T , typename... Tail>
void pdebug (T head, Tail... tail) const
 
void pinfo () const
 
template<typename T , typename... Tail>
void pinfo (T head, Tail... tail) const
 
void pwarning () const
 
template<typename T , typename... Tail>
void pwarning (T head, Tail... tail) const
 
int get_level ()
 
unsigned int get_Ndebug ()
 
unsigned int get_Ninfo ()
 
unsigned int get_Nwarning ()
 
unsigned int get_Nerror ()
 
unsigned int get_Ncustom ()
 
void set_level (std::string level)
 

Protected Types

enum  _LOG_LEVEL {
  _notset = 0 , _debug = 10 , _info = 20 , _warning = 30 ,
  _error = 40 , _critical = 100
}
 

Protected Member Functions

void set_level (int level)
 

Static Protected Attributes

static int log_level = 20
 
static unsigned int count_debug =0
 
static unsigned int count_info =0
 
static unsigned int count_warning =0
 
static unsigned int count_error =0
 
static unsigned int count_custom_log =0
 

Detailed Description

A thread safe(really?) Logging class to handle the message output and the error. It is based on a log level scheme. There is a static attribute log_level that has some integer value by default (20 or 10 id DEBUG has been enabled). Then a given message is sent in output only if its level is larger than log_level. A new log_level can be set with the method set_level. The possible logging message are debug(lvl 10), info(lvl 20), warning(lvl 30), error(lvl 40), critical (no level always printed). Critical raises automatically an exception, while in error is optional. A general log method can be used to print output with a custom level.

Member Enumeration Documentation

◆ _LOG_LEVEL

An enum storing the various log level.

Enumerator
_notset 

lvl 0, Notset general value

_debug 

lvl 10, Debug level

_info 

lvl 20, Info level

_warning 

lvl 30, Warning level

_error 

lvl 40, Error level

_critical 

lvl 100, Only critical level

Constructor & Destructor Documentation

◆ SevnLogging() [1/2]

sevnstd::SevnLogging::SevnLogging ( )
inline

Default class constructor.

◆ SevnLogging() [2/2]

sevnstd::SevnLogging::SevnLogging ( int  level)
inline

Class constructor that set the static log level attribute.

Parameters
levellog level to set.

◆ ~SevnLogging()

sevnstd::SevnLogging::~SevnLogging ( )
inline

Default class destructor.

Member Function Documentation

◆ critical() [1/2]

void sevnstd::SevnLogging::critical ( std::string  errstate,
const char *  file_input = nullptr,
int  line_input = -1 
) const

Logs a message with std::cerr level CRITICAL (no level) on this logger and throw an sevnerr exception. This message will never be filtered out.

Parameters
errstatemessage to log.
file_inputNull or FILE. if FILE is used the message logs the name of the file where the log is called.
line_inputNull or LINE. if LINE is used the message logs the row number in the file where the log is called.

◆ critical() [2/2]

template<class E >
void sevnstd::SevnLogging::critical ( std::string  errstate,
const char *  file_input = nullptr,
int  line_input = -1,
E &&  err = nullptr 
) const
inline

Logs a message with std::cerr level CRITICAL (no level) on this logger and throw an exception E.

Template Parameters
Eexception derived from the class sevnerr
Parameters
errstatemessage to log.
file_inputfile_input Null or FILE. if FILE is used the message logs the name of the file where the log is called.
line_inputline_input Null or LINE. if LINE is used the message logs the row number in the file where the log is called.
errexception derived from the class sevnerr

◆ debug()

void sevnstd::SevnLogging::debug ( std::string  errstate,
const char *  file_input = nullptr,
int  line_input = -1 
) const

Logs a message to std::cout with level DEBUG (lvl 10) on this logger.

Parameters
errstatemessage to log.
file_inputNull or FILE. if FILE is used the message logs the name of the file where the log is called.
line_inputNull or LINE. if LINE is used the message logs the row number in the file where the log is called.

◆ error() [1/2]

void sevnstd::SevnLogging::error ( std::string  errstate,
const char *  file_input = nullptr,
int  line_input = -1,
bool  stop = true 
) const

Logs a message with std::cerr level ERROR (lvl 40) on this logger and throw an exception.

Parameters
errstatemessage to log.
file_inputNull or FILE. if FILE is used the message logs the name of the file where the log is called.
line_inputNull or LINE. if LINE is used the message logs the row number in the file where the log is called.
stopif true throw a sevnerr exception.

◆ error() [2/2]

template<class E >
void sevnstd::SevnLogging::error ( std::string  errstate,
const char *  file_input = nullptr,
int  line_input = -1,
bool  stop = true,
E &&  err = nullptr 
) const
inline
Template Parameters
Eexception derived from the class sevnerr
Parameters
errstatemessage to log.
file_inputfile_input Null or FILE. if FILE is used the message logs the name of the file where the log is called.
line_inputline_input Null or LINE. if LINE is used the message logs the row number in the file where the log is called.
stopif if true throw a err exception (see below).
errexception derived from the class sevnerr

◆ get_level()

int sevnstd::SevnLogging::get_level ( )
inline

Logs a message to std::cout with level DEBUG (lvl 10) on this logger.

Template Parameters
Argspack of Variadic arguments
Parameters
argsargs to be printed Logs a message to std::cout with level DEBUG (lvl 10) on this logger.
Template Parameters
Argspack of Variadic arguments
Parameters
argsargs to be printed Get the current level of this logger
Returns
log level.

◆ get_Ncustom()

unsigned int sevnstd::SevnLogging::get_Ncustom ( )
inline

Get the current counter of custom log calls

Returns
current counter of custom log calls

◆ get_Ndebug()

unsigned int sevnstd::SevnLogging::get_Ndebug ( )
inline

Get the current counter of debug calls

Returns
current counter of debug calls

◆ get_Nerror()

unsigned int sevnstd::SevnLogging::get_Nerror ( )
inline

Get the current counter of error calls

Returns
current counter of error calls

◆ get_Ninfo()

unsigned int sevnstd::SevnLogging::get_Ninfo ( )
inline

Get the current counter of info calls

Returns
current counter of info calls

◆ get_Nwarning()

unsigned int sevnstd::SevnLogging::get_Nwarning ( )
inline

Get the current counter of warning calls

Returns
current counter of warning calls

◆ info()

void sevnstd::SevnLogging::info ( std::string  errstate,
const char *  file_input = nullptr,
int  line_input = -1 
) const

Logs a message to std::cout with level INFO (lvl 20) on this logger.

Parameters
errstatemessage to log.
file_inputNull or FILE. if FILE is used the message logs the name of the file where the log is called.
line_inputNull or LINE. if LINE is used the message logs the row number in the file where the log is called.

◆ log()

void sevnstd::SevnLogging::log ( int  level,
std::string  errstate,
const char *  file_input = nullptr,
int  line_input = -1,
int  stop = 0 
) const

Logs a message to std::cout with integer level on this logger.

Parameters
levelmessage level.
errstatemessage to log.
file_inputNull or FILE. if FILE is used the message logs the name of the file where the log is called.
line_inputNull or LINE. if LINE is used the message logs the row number in the file where the log is called.
stopif != 0, throw a runtime exception.

◆ pdebug() [1/2]

void sevnstd::SevnLogging::pdebug ( ) const
inline

Variadic prints.

◆ pdebug() [2/2]

template<typename T , typename... Tail>
void sevnstd::SevnLogging::pdebug ( head,
Tail...  tail 
) const
inline

◆ pinfo() [1/2]

void sevnstd::SevnLogging::pinfo ( ) const
inline

◆ pinfo() [2/2]

template<typename T , typename... Tail>
void sevnstd::SevnLogging::pinfo ( head,
Tail...  tail 
) const
inline

◆ pwarning() [1/2]

void sevnstd::SevnLogging::pwarning ( ) const
inline

◆ pwarning() [2/2]

template<typename T , typename... Tail>
void sevnstd::SevnLogging::pwarning ( head,
Tail...  tail 
) const
inline

◆ set_level() [1/2]

void sevnstd::SevnLogging::set_level ( int  level)
inlineprotected

Set the static log_level.

Parameters
level

◆ set_level() [2/2]

void sevnstd::SevnLogging::set_level ( std::string  level)

Public interface to change log level

Parameters
levelstring, can be: dubug, info, warning,error.

◆ warning()

void sevnstd::SevnLogging::warning ( std::string  errstate,
const char *  file_input = nullptr,
int  line_input = -1 
) const

Logs a message with std::cerr level WARNING (lvl 30) on this logger.

Parameters
errstatemessage to log.
file_inputNull or FILE. if FILE is used the message logs the name of the file where the log is called.
line_inputNull or LINE. if LINE is used the message logs the row number in the file where the log is called.

Member Data Documentation

◆ count_custom_log

unsigned int sevnstd::SevnLogging::count_custom_log =0
staticprotected

Counter storing how many times a custom log has been called

◆ count_debug

unsigned int sevnstd::SevnLogging::count_debug =0
staticprotected

Counter storing how many times a debug log has been called

◆ count_error

unsigned int sevnstd::SevnLogging::count_error =0
staticprotected

Counter storing how many times an error log has been called

◆ count_info

unsigned int sevnstd::SevnLogging::count_info =0
staticprotected

Counter storing how many times a info log has been called

◆ count_warning

unsigned int sevnstd::SevnLogging::count_warning =0
staticprotected

Counter storing how many times a warning log has been called

◆ log_level

int sevnstd::SevnLogging::log_level = 20
staticprotected

Current log level


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