glogging
Loading...
Searching...
No Matches
GLogger Class Reference

Handles structured logging with verbosity and debug levels. More...

#include <glogger.h>

Collaboration diagram for GLogger:
Collaboration graph

Public Member Functions

 GLogger (const std::shared_ptr< GOptions > &gopts, const std::string &cname, const std::string &lname="")
 Constructs a GLogger instance.
 
 GLogger ()=default
 
 ~GLogger ()
 
template<typename... Args>
void debug (debug_type type, Args &&... args) const
 Logs a debug message if the debug level is nonzero.
 
template<typename... Args>
void info (int level, Args &&... args) const
 Logs an info message, conditionally based on verbosity level.
 
template<typename... Args>
void info (Args &&... args) const
 Overloaded version of info() with the default level = 0.
 
template<typename... Args>
void warning (Args &&... args) const
 Logs a warning message.
 
template<typename... Args>
void error (int exit_code, Args &&... args) const
 Logs an error message and exits the application.
 
template<typename... Args>
void critical (Args &&... args) const
 Logs a critical message. Always printed.
 
std::string get_class_name () const
 

Detailed Description

GLogger manages output messages categorized as debug, info, warning, error, and critical. It allows conditional printing based on verbosity and debug flags, supports colored output, and automatically adds a counter to each message.

Definition at line 43 of file glogger.h.

Constructor & Destructor Documentation

◆ GLogger() [1/2]

GLogger::GLogger ( const std::shared_ptr< GOptions > & gopts,
const std::string & cname,
const std::string & lname = "" )
inlineexplicit
Parameters
goptsShared Pointer to GOptions instance used for verbosity/debug lookup.
cnameNot used currently: can be class name or additional info of who's calling the log
lnameThe logger name

Definition at line 51 of file glogger.h.

◆ GLogger() [2/2]

GLogger::GLogger ( )
default

◆ ~GLogger()

GLogger::~GLogger ( )
inline

Definition at line 61 of file glogger.h.

Member Function Documentation

◆ critical()

template<typename... Args>
void GLogger::critical ( Args &&... args) const
inline
Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
argsMessage parts to be logged.

Definition at line 173 of file glogger.h.

◆ debug()

template<typename... Args>
void GLogger::debug ( debug_type type,
Args &&... args ) const
inline

Uses variadic templates with perfect forwarding and fold expressions to construct the log message.

Template Parameters
ArgsVariadic template parameters representing any streamable types.
Parameters
typeThe debug message type (NORMAL, CONSTRUCTOR, or DESTRUCTOR).
argsThe message components.

This method uses:

  • Variadic templates to accept any number of arguments.
  • Perfect forwarding with std::forward to preserve value categories.
  • Fold expressions to stream all arguments into an ostringstream.

Definition at line 78 of file glogger.h.

◆ error()

template<typename... Args>
void GLogger::error ( int exit_code,
Args &&... args ) const
inline
Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
exit_codeThe program exit code.
argsMessage parts to be logged before exiting.
Note
This function is marked [[noreturn]] because it always terminates the process.

Definition at line 158 of file glogger.h.

◆ get_class_name()

std::string GLogger::get_class_name ( ) const
inline

Definition at line 180 of file glogger.h.

◆ info() [1/2]

template<typename... Args>
void GLogger::info ( Args &&... args) const
inline
Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
argsStreamable message components.

Definition at line 131 of file glogger.h.

◆ info() [2/2]

template<typename... Args>
void GLogger::info ( int level,
Args &&... args ) const
inline
Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
levelThe importance level (0 = always, 1 = only if verbosity > 0, 2 = more detailed).
argsMessage components to log.

If an invalid verbosity level is requested, logs an error and exits.

Definition at line 109 of file glogger.h.

◆ warning()

template<typename... Args>
void GLogger::warning ( Args &&... args) const
inline
Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
argsMessage parts to be logged.

Always prints regardless of verbosity or debug levels.

Definition at line 142 of file glogger.h.


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