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

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

#include <glogger.h>

Public Member Functions

 GLogger (const std::shared_ptr< GOptions > &gopts, const std::string &cname, const std::string &lname="")
 Constructs a GLogger instance and resolves its runtime configuration.
 
 GLogger ()=default
 Default constructor.
 
 ~GLogger ()
 Destructor.
 
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 informational message, optionally gated by verbosity level.
 
template<typename... Args>
void info (Args &&... args) const
 Convenience overload of info() that defaults to 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 terminates the process.
 
template<typename... Args>
void critical (Args &&... args) const
 Logs a critical message.
 
std::string get_class_name () const
 Returns the caller-provided class name associated with this logger instance.
 

Detailed Description

GLogger centralizes formatted output for simulation components. Messages are emitted to the Geant4 streams (G4cout/G4cerr) and can be filtered based on configuration obtained from GOptions.

Key responsibilities:

  • Apply verbosity/debug filtering consistently across the codebase.
  • Render standardized message headers including a per-instance atomic counter.
  • Provide convenience APIs that accept variadic "streamable" arguments, allowing callers to build messages without manual string formatting.
Filtering model
  • Debug messages are emitted only when the resolved debug level is nonzero.
  • Info messages can be emitted at level 0, 1, or 2, each gated by the resolved verbosity level.
  • Warning and critical messages are always emitted.
  • Error messages are emitted and then the process terminates with an exit code.
Warning
This class writes to shared output streams. While the internal counter is thread-safe, output interleaving is still possible depending on the underlying stream behavior.

Definition at line 84 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

The constructor queries the provided GOptions to resolve:

  • The verbosity level associated with lname.
  • The debug level associated with lname.

It also emits a constructor-style debug message via debug() (only if debug is enabled for this logger name).

Parameters
goptsShared pointer to the GOptions instance used for verbosity/debug lookup.
cnameCaller-provided class name (informational; currently not used for filtering).
lnameThe logger name (subsystem identifier). This is used as the lookup key in GOptions.

Definition at line 102 of file glogger.h.

◆ GLogger() [2/2]

GLogger::GLogger ( )
default

This constructor does not resolve verbosity/debug settings and leaves the logger in a default-initialized state. It is primarily useful for scenarios where a logger instance must exist before configuration is available.

Note
If you use this constructor, ensure logger_name, verbosity_level, and debug_level are set through the normal construction path before relying on filtering behavior.

◆ ~GLogger()

GLogger::~GLogger ( )
inline

Emits a destructor-style debug message via debug() (only if debug is enabled).

Definition at line 130 of file glogger.h.

Member Function Documentation

◆ critical()

template<typename... Args>
void GLogger::critical ( Args &&... args) const
inline

Critical messages are always printed and are intended for high-visibility output that should stand out (for example : major state transitions, run headers, or emphasized notices).

Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
argsMessage parts to be logged.

Definition at line 268 of file glogger.h.

◆ debug()

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

This method builds a single message string from args... using stream insertion into an std::ostringstream. It then prints the message with a standardized header and optional constructor/destructor markers depending on type.

Template Parameters
ArgsVariadic template parameters representing any streamable types.
Parameters
typeThe debug message classification : NORMAL, CONSTRUCTOR, or DESTRUCTOR.
argsThe message components. Each argument must be insertable into std::ostream.

Implementation techniques used:

  • Variadic templates for a flexible number of message components.
  • Perfect forwarding (std::forward) to preserve value categories.
  • Fold expression (oss << ... << arg) to stream all arguments.
Note
Debug output is suppressed entirely when debug_level == 0.

Definition at line 151 of file glogger.h.

◆ error()

template<typename... Args>
void GLogger::error ( int exit_code,
Args &&... args ) const
inline

This method prints:

  • The provided message.
  • The explicit exit code line.

Then it terminates the process via std::exit(exit_code).

Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
exit_codeThe program exit code to return to the calling environment.
argsMessage parts to be logged before exiting.
Note
This function is marked [[noreturn]] because it always terminates the process.

Definition at line 250 of file glogger.h.

◆ get_class_name()

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

This value is currently informational and can be used by callers to include the originating class in their own message composition if desired.

Returns
The stored class name string.

Definition at line 282 of file glogger.h.

◆ info() [1/2]

template<typename... Args>
void GLogger::info ( Args &&... args) const
inline

This overload is intended for the most common informational messages that should always be printed irrespective of verbosity configuration.

Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
argsStreamable message components.

Definition at line 214 of file glogger.h.

◆ info() [2/2]

template<typename... Args>
void GLogger::info ( int level,
Args &&... args ) const
inline

Info messages support three levels of detail:

  • level 0 : Always printed (baseline information).
  • level 1 : Printed only when verbosity_level > 0.
  • level 2 : Printed only when verbosity_level > 1 (most detailed).
Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
levelThe info importance/detail level (0, 1, or 2).
argsMessage components to log. Each argument must be stream-insertable.
Exceptions
(processtermination) If level is not 0, 1, or 2, this method prints a fatal error and terminates the process with EC_WRONG_VERBOSITY_LEVEL.

Definition at line 188 of file glogger.h.

◆ warning()

template<typename... Args>
void GLogger::warning ( Args &&... args) const
inline

Warning messages are always printed and are typically used for recoverable problems, suspicious conditions, or degraded behavior that does not warrant immediate termination.

Template Parameters
ArgsVariadic template parameters for any streamable types.
Parameters
argsMessage parts to be logged.

This method does not consult verbosity or debug levels.

Definition at line 228 of file glogger.h.


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