LogIt++
Loading...
Searching...
No Matches
logit Namespace Reference

The primary namespace for the LogIt++ library. More...

Classes

class  ConsoleLogger
 Logger that outputs log messages to the console with optional color coding. More...
 
class  FileLogger
 Logger that outputs log messages to files with date-based rotation and old file deletion. More...
 
struct  FormatInstruction
 Structure to store log formatting instructions. More...
 
interface  ILogFormatter
 Interface for formatting log records. More...
 
interface  ILogger
 Interface for loggers that handle log message output. More...
 
class  Logger
 Singleton class that manages multiple loggers and formatters. More...
 
struct  LogRecord
 Stores log metadata and content. More...
 
class  LogStream
 A stream-based logger that collects log messages using the << operator. More...
 
struct  PathComponents
 Structure to hold the root and components of a path. More...
 
class  PatternCompiler
 Compiler for log formatting patterns. More...
 
class  SimpleLogFormatter
 A simple log formatter that formats log messages based on a user-defined pattern. More...
 
class  TaskExecutor
 A thread-safe task executor that processes tasks in a dedicated worker thread. More...
 
class  UniqueFileLogger
 Logger that writes each log message to a unique file with date-time and hash in the filename. More...
 
struct  VariableValue
 Structure for storing values of various types, including enumerations. More...
 

Typedefs

using crev_it_t = std::string::const_reverse_iterator
 

Enumerations

enum class  LogLevel {
  LOG_LVL_TRACE , LOG_LVL_DEBUG , LOG_LVL_INFO , LOG_LVL_WARN ,
  LOG_LVL_ERROR , LOG_LVL_FATAL
}
 Logging levels. More...
 
enum class  TextColor {
  Black , DarkRed , DarkGreen , DarkYellow ,
  DarkBlue , DarkMagenta , DarkCyan , LightGray ,
  DarkGray , Red , Green , Yellow ,
  Blue , Magenta , Cyan , White
}
 Text colors for console output. More...
 
enum class  LoggerParam { LastFileName , LastFilePath , LastLogTimestamp , TimeSinceLastLog }
 Enumeration for different logger parameters that can be retrieved. More...
 

Functions

const char * to_c_str (const LogLevel &level, const int &mode=0)
 Convert LogLevel to a C-style string representation.
 
std::string to_string (const LogLevel &level, const int &mode=0)
 Convert LogLevel to a std::string representation.
 
const char * to_c_str (const TextColor &color)
 Convert TextColor to a C-style string (ANSI escape codes).
 
std::string to_string (const TextColor &color)
 Convert TextColor to a std::string (ANSI escape codes).
 
std::string get_log_level_color (const LogLevel &log_level)
 Get the ANSI color code associated with a log level.
 
std::vector< VariableValueargs_to_array (std::vector< std::string >::const_iterator name_iter)
 Base case of recursion for argument conversion — when there are no more arguments.
 
template<typename T , typename... Ts>
std::vector< VariableValueargs_to_array (std::vector< std::string >::const_iterator name_iter, const T &first_arg, const Ts &... args)
 Recursive function to convert arguments into an array of tuples (name, value).
 
bool is_closing_template (crev_it_t left_it, crev_it_t right_it)
 Checks if the '>' character is the closing of a template argument list.
 
std::vector< std::string > split_arguments (const std::string &all_names)
 Splits a string of argument names into individual names, ignoring nested templates, parentheses, and quotes.
 
std::string format (const char *fmt,...)
 Formats a string according to the specified format.
 
std::string format (const std::string &fmt,...)
 Formats a string according to the specified format using std::string.
 
std::string get_exe_path ()
 Retrieves the directory of the executable file.
 
std::vector< std::string > get_list_files (const std::string &path)
 Recursively retrieves a list of all files in a directory.
 
std::string get_file_name (const std::string &file_path)
 Extracts the file name from a full file path.
 
PathComponents split_path (const std::string &path)
 Splits a path into its root and components.
 
std::string make_relative (const std::string &file_path, const std::string &base_path)
 Computes the relative path from base_path to file_path.
 
bool is_file (const std::string &path)
 Checks if a path represents a file (by checking for an extension).
 
void create_directories (const std::string &path)
 Creates directories recursively for the given path.
 

Detailed Description

The primary namespace for the LogIt++ library.

Typedef Documentation

◆ crev_it_t

using logit::crev_it_t = std::string::const_reverse_iterator

Definition at line 39 of file argument_utils.hpp.

Enumeration Type Documentation

◆ LoggerParam

enum class logit::LoggerParam
strong

Enumeration for different logger parameters that can be retrieved.

Enumerator
LastFileName 

The name of the last file written to.

LastFilePath 

The full path of the last file written to.

LastLogTimestamp 

The timestamp of the last log.

TimeSinceLastLog 

The time elapsed since the last log in seconds.

Definition at line 46 of file Enums.hpp.

◆ LogLevel

enum class logit::LogLevel
strong

Logging levels.

Enumerator
LOG_LVL_TRACE 

Trace level logging.

LOG_LVL_DEBUG 

Debug level logging.

LOG_LVL_INFO 

Information level logging.

LOG_LVL_WARN 

Warning level logging.

LOG_LVL_ERROR 

Error level logging.

LOG_LVL_FATAL 

Fatal level logging.

Definition at line 14 of file Enums.hpp.

◆ TextColor

enum class logit::TextColor
strong

Text colors for console output.

Enumerator
Black 
DarkRed 
DarkGreen 
DarkYellow 
DarkBlue 
DarkMagenta 
DarkCyan 
LightGray 
DarkGray 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White 

Definition at line 25 of file Enums.hpp.

Function Documentation

◆ args_to_array() [1/2]

std::vector< VariableValue > logit::args_to_array ( std::vector< std::string >::const_iterator name_iter)
inline

Base case of recursion for argument conversion — when there are no more arguments.

Parameters
name_iterIterator for the argument name list.
Returns
An empty vector, as there are no more arguments to process.

Definition at line 16 of file argument_utils.hpp.

◆ args_to_array() [2/2]

template<typename T , typename... Ts>
std::vector< VariableValue > logit::args_to_array ( std::vector< std::string >::const_iterator name_iter,
const T & first_arg,
const Ts &... args )

Recursive function to convert arguments into an array of tuples (name, value).

Template Parameters
TType of the first argument.
TsTypes of the remaining arguments.
Parameters
name_iterIterator for the argument name list.
first_argThe first argument.
argsThe remaining arguments.
Returns
A vector of tuples containing argument names and values.

Definition at line 28 of file argument_utils.hpp.

◆ create_directories()

void logit::create_directories ( const std::string & path)

Creates directories recursively for the given path.

Parameters
pathThe directory path to create.
Exceptions
std::runtime_errorif the directories cannot be created.

Definition at line 336 of file path_utils.hpp.

◆ format() [1/2]

std::string logit::format ( const char * fmt,
... )
inline

Formats a string according to the specified format.

This function formats a string using either the custom implementation based on vsnprintf) or the fmt library, depending on whether the macro LOGIT_USE_FMT_LIB is defined.

Parameters
fmtThe format string (similar to printf format).
...A variable number of arguments matching the format string.
See also
https://habr.com/ru/articles/318962/
Returns
A formatted std::string.

Definition at line 27 of file format.hpp.

◆ format() [2/2]

std::string logit::format ( const std::string & fmt,
... )
inline

Formats a string according to the specified format using std::string.

This function formats a string using either the custom implementation based on vsnprintf) or the fmt library, depending on whether the macro LOGIT_USE_FMT_LIB is defined.

Parameters
fmtThe format string (similar to printf format) provided as std::string.
...A variable number of arguments matching the format string.
Returns
A formatted std::string.

Definition at line 67 of file format.hpp.

◆ get_exe_path()

std::string logit::get_exe_path ( )

Retrieves the directory of the executable file.

Returns
A string containing the directory path of the executable.

Definition at line 37 of file path_utils.hpp.

◆ get_file_name()

std::string logit::get_file_name ( const std::string & file_path)

Extracts the file name from a full file path.

Parameters
file_pathThe full file path as a string.
Returns
The extracted file name, or the full string if no directory separator is found.

Definition at line 178 of file path_utils.hpp.

◆ get_list_files()

std::vector< std::string > logit::get_list_files ( const std::string & path)

Recursively retrieves a list of all files in a directory.

Parameters
pathThe directory path to search.
Returns
A vector of strings containing the full paths of all files found.

Definition at line 89 of file path_utils.hpp.

◆ get_log_level_color()

std::string logit::get_log_level_color ( const LogLevel & log_level)
inline

Get the ANSI color code associated with a log level.

Parameters
log_levelThe log level.
Returns
ANSI escape code string representing the color for the log level.

Definition at line 131 of file Enums.hpp.

◆ is_closing_template()

bool logit::is_closing_template ( crev_it_t left_it,
crev_it_t right_it )

Checks if the '>' character is the closing of a template argument list.

Parameters
left_itIterator pointing to the '>' character.
right_itIterator pointing to the end of the string.
Returns
true if the '>' character closes a template argument list, false otherwise.

Definition at line 45 of file argument_utils.hpp.

◆ is_file()

bool logit::is_file ( const std::string & path)
inline

Checks if a path represents a file (by checking for an extension).

Parameters
pathThe path to check.
Returns
True if the path represents a file, false otherwise.

Definition at line 327 of file path_utils.hpp.

◆ make_relative()

std::string logit::make_relative ( const std::string & file_path,
const std::string & base_path )

Computes the relative path from base_path to file_path.

Parameters
file_pathThe target file path.
base_pathThe base path from which to compute the relative path.
Returns
A string representing the relative path from base_path to file_path.

Definition at line 273 of file path_utils.hpp.

◆ split_arguments()

std::vector< std::string > logit::split_arguments ( const std::string & all_names)
inline

Splits a string of argument names into individual names, ignoring nested templates, parentheses, and quotes.

Parameters
all_namesThe string containing all argument names.
Returns
A vector of strings with individual argument names.

Definition at line 63 of file argument_utils.hpp.

◆ split_path()

PathComponents logit::split_path ( const std::string & path)

Splits a path into its root and components.

Parameters
pathThe path to split.
Returns
A PathComponents object containing the root and components of the path.

Definition at line 229 of file path_utils.hpp.

◆ to_c_str() [1/2]

const char * logit::to_c_str ( const LogLevel & level,
const int & mode = 0 )
inline

Convert LogLevel to a C-style string representation.

Parameters
levelThe log level.
modeThe output mode (0 for full name, 1 for abbreviation).
Returns
C-style string representing the log level.

Definition at line 57 of file Enums.hpp.

◆ to_c_str() [2/2]

const char * logit::to_c_str ( const TextColor & color)
inline

Convert TextColor to a C-style string (ANSI escape codes).

Parameters
colorThe text color.
Returns
C-style string representing the ANSI escape code for the color.

Definition at line 96 of file Enums.hpp.

◆ to_string() [1/2]

std::string logit::to_string ( const LogLevel & level,
const int & mode = 0 )
inline

Convert LogLevel to a std::string representation.

Parameters
levelThe log level.
modeThe output mode (0 for full name, 1 for abbreviation).
Returns
std::string representing the log level.

Definition at line 89 of file Enums.hpp.

◆ to_string() [2/2]

std::string logit::to_string ( const TextColor & color)
inline

Convert TextColor to a std::string (ANSI escape codes).

Parameters
colorThe text color.
Returns
std::string representing the ANSI escape code for the color.

Преобразование TextColor в строку (ANSI escape codes)

Definition at line 124 of file Enums.hpp.