Log utilities
- Here you can find some tools for logging purpose :
The verbosity is defined with the enum Log level
A Logger Manager is also provided
Macros to log while taking the verbosity into account
Log level
The verbosity of the log can be set using
-
enum class io::LogLevel
Describes the verbosity of the logger.
See also
See also
io::SetLogLevel
Values:
-
enumerator OFF
No log at all.
-
enumerator ERROR
Only Error messages.
-
enumerator WARNING
Error and Warning messages.
-
enumerator INFO
Error, Warning and Info messages.
-
enumerator EXTENDED
Error, Warning, Info and Extended messages.
-
enumerator DEBUG
Error, Warning, Info and Debug messages.
-
enumerator OFF
Loggers
Log file
A logfile can be managed through
TeeLogger
Logger Manager
One can create, access and set the verbosity an instance of TeeLogger or Log file using the following class :
-
class LoggerManager
Store and give access to TeeLoggers.
Public Static Functions
-
static TeeLogger &GetLogger(std::string_view name = "")
Get or create a TeeLogger.
- Parameters:
name – name of the logger, empty string for default name
- Returns:
A reference to the logger
-
static void ClearLogger(std::string_view name = "")
Clear a logger.
- Parameters:
name – name of the logger, empty string for default name
-
static void SetLogLevel(LogLevel level, std::string_view name = "")
Set the loglevel of a TeeLogger.
- Parameters:
name – name of the logger, empty string for default name
level – the log level
-
static inline void SetDefaultLogLevel(LogLevel level)
Set the default verbosity.
- Parameters:
level – the verbosity
-
static inline void SetDefaultName(std::string_view name)
Set the default name.
- Parameters:
name – name of the logger
-
static FileLogger &GetFileLogger(std::string_view name)
Get or create a FileLogger.
- Parameters:
name – name of the logger
- Returns:
A reference to the logger
-
static void ClearFileLogger(std::string_view name)
Clear a FileLogger.
- Parameters:
name – name of the logger
-
static void SetFileLogLevel(LogLevel level, std::string_view name)
Set the loglevel of a FileLogger.
- Parameters:
name – name of the logger
level – the log level
-
static void ClearAllLoggers()
Clear every logger (file or tee)
-
static TeeLogger &GetLogger(std::string_view name = "")
Logger
Both the Log file and the TeeLogger inherits from the following class:
-
template<typename ostream>
class Logger Interface for logger.
- Template Parameters:
ostream – The type of output stream
Macros
Main macros for TeeLogger manipulation
-
ERORLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::ERROR.
- Throws if:
the main io::TeeLogger has not been created
-
WARNLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::WARNING.
- Throws if:
the main io::TeeLogger has not been created
-
INFOLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::INFO.
- Throws if:
the main io::TeeLogger has not been created
-
DBUGLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::DEBUG.
- Throws if:
the main io::TeeLogger has not been created
-
ERORLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::ERROR.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
-
WARNLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::WARNING.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
-
INFOLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::INFO.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
-
DBUGLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::DEBUG.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
Main macros for Log file manipulation
-
EROR(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::ERROR.
- Parameters:
log – the log
-
WARN(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::WARNING.
- Parameters:
log – the log
-
INFO(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::INFO.
- Parameters:
log – the log
-
DBUG(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::DEBUG.
- Parameters:
log – the log
-
EROR_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::ERROR.
- Parameters:
log – the log
header – the message
range – the range
-
WARN_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::WARNING.
- Parameters:
log – the log
header – the message
range – the range
-
INFO_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::INFO.
- Parameters:
log – the log
header – the message
range – the range
-
DBUG_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::DEBUG.
- Parameters:
log – the log
header – the message
range – the range
Full reference
log utilities
Defines
-
COND_STATEMENT(cond)
Execute the following instruction provided that a condition is satified.
- Parameters:
cond – the condition
expands toCOND_STATEMENT(cond) instruction
if(!cond){} else instruction
-
EROR(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::ERROR.
- Parameters:
log – the log
-
WARN(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::WARNING.
- Parameters:
log – the log
-
INFO(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::INFO.
- Parameters:
log – the log
-
EXTD(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::EXTENDED.
- Parameters:
log – the log
-
DBUG(log)
Log a message in a stream, provided that the log level is >= io::LogLevel::DEBUG.
- Parameters:
log – the log
-
ERORLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::ERROR.
- Throws if:
the main io::TeeLogger has not been created
-
WARNLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::WARNING.
- Throws if:
the main io::TeeLogger has not been created
-
INFOLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::INFO.
- Throws if:
the main io::TeeLogger has not been created
-
EXTDLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::EXTENDED.
- Throws if:
the main io::TeeLogger has not been created
-
DBUGLOG
Log a message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::DEBUG.
- Throws if:
the main io::TeeLogger has not been created
-
EROR_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::ERROR.
- Parameters:
log – the log
header – the message
range – the range
-
WARN_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::WARNING.
- Parameters:
log – the log
header – the message
range – the range
-
INFO_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::INFO.
- Parameters:
log – the log
header – the message
range – the range
-
EXTD_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::EXTENDED.
- Parameters:
log – the log
header – the message
range – the range
-
DBUG_RANGE(log, header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::DEBUG.
- Parameters:
log – the log
header – the message
range – the range
-
ERORLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::ERROR.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
-
WARNLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::WARNING.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
-
INFOLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::INFO.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
-
EXTDLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::EXTENDED.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
-
DBUGLOG_RANGE(header, range)
Log a range with a header message in the main io::TeeLogger, provided that the log level is >= io::LogLevel::DEBUG.
- Parameters:
header – the message
range – the range
- Throws if:
the main io::TeeLogger has not been created
-
PRINT_PERCENTAGE(val)
print a numeric value as a percentage, with a precision of 2
- Parameters:
val – the value
-
PRINT_ENUM(val)
print an enum value created with MAKE_DTO_ENUM as a string
- Parameters:
val – the value
-
namespace io
Functions
-
template<typename Range>
std::ostream &print_range(std::ostream &os, Range const &range) Print every object of a range in a stream.
- Template Parameters:
Range – the type of range
- Parameters:
os – the ostream
range – the range of object
-
template<typename T>
std::ostream &print(std::ostream &os, T const &obj) Print an object in a stream.
- Template Parameters:
T – the type of object
- Parameters:
os – the ostream
obj – the object
-
template<typename T>
std::ostream &print(std::ostream &os, const std::vector<T> &range) Print a range of object in a stream.
- Template Parameters:
T – the type of object
- Parameters:
os – the ostream
range – the object
-
class LoggerManager
- #include <log.hh>
Store and give access to TeeLoggers.
Public Static Functions
-
static TeeLogger &GetLogger(std::string_view name = "")
Get or create a TeeLogger.
- Parameters:
name – name of the logger, empty string for default name
- Returns:
A reference to the logger
-
static void ClearLogger(std::string_view name = "")
Clear a logger.
- Parameters:
name – name of the logger, empty string for default name
-
static void SetLogLevel(LogLevel level, std::string_view name = "")
Set the loglevel of a TeeLogger.
- Parameters:
name – name of the logger, empty string for default name
level – the log level
-
static inline void SetDefaultLogLevel(LogLevel level)
Set the default verbosity.
- Parameters:
level – the verbosity
-
static inline void SetDefaultName(std::string_view name)
Set the default name.
- Parameters:
name – name of the logger
-
static FileLogger &GetFileLogger(std::string_view name)
Get or create a FileLogger.
- Parameters:
name – name of the logger
- Returns:
A reference to the logger
-
static void ClearFileLogger(std::string_view name)
Clear a FileLogger.
- Parameters:
name – name of the logger
-
static void SetFileLogLevel(LogLevel level, std::string_view name)
Set the loglevel of a FileLogger.
- Parameters:
name – name of the logger
level – the log level
-
static void ClearAllLoggers()
Clear every logger (file or tee)
Private Static Attributes
-
static std::unordered_map<std::string, TeeLogger, string_hash, std::equal_to<>> _tee_loggers
static storage of the tee logger
-
static std::string _logfile_name = std::string("default")
default log file name
-
static std::unordered_map<std::string, FileLogger, string_hash, std::equal_to<>> _file_loggers
static storage of the file logger
-
static TeeLogger &GetLogger(std::string_view name = "")
-
template<typename Range>