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 constructor.
 ~GLogger ()
 Destructor.
template<typename... Args>
void debug (debug_type type, std::string_view message, Args &&... args) const
 Logs a debug message if the debug level is nonzero.
template<typename... Args>
void info (int level, std::string_view message, Args &&... args) const
 Logs a complete message template, optionally gated by verbosity level.
template<typename Message, typename... Args>
requires std::is_convertible_v<Message, std::string_view>
void info (Message &&message, Args &&... args) const
 Convenience overload of info() that defaults to level 0.
template<typename... Args>
void warning (std::string_view message, Args &&... args) const
 Logs a warning message.
template<typename... Args>
void error (int exit_code, std::string_view message, Args &&... args) const
 Logs an error message and terminates the process.
template<typename... Args>
void critical (std::string_view message, Args &&... args) const
 Logs a critical message.
template<typename... Args>
void infoTemplate (int level, std::string_view message, Args &&... args) const
 Transitional alias for info(), with identical template and filtering semantics.
template<typename Message, typename... Args>
requires std::is_convertible_v<Message, std::string_view>
void infoTemplate (Message &&message, Args &&... args) const
 Logs a message template at info level 0; see infoTemplate(int, std::string_view, Args&&...).
template<typename... Args>
void debugTemplate (debug_type type, std::string_view message, Args &&... args) const
 Transitional alias for debug().
template<typename... Args>
void warningTemplate (std::string_view message, Args &&... args) const
 Transitional alias for warning().
template<typename... Args>
void errorTemplate (int exit_code, std::string_view message, Args &&... args) const
 Transitional alias for error().
template<typename... Args>
void criticalTemplate (std::string_view message, Args &&... args) const
 Transitional alias for critical().
std::string get_class_name () const
 Returns the caller-provided class name associated with this logger instance.
const std::string & get_language () const
 Normalized language selected from options, environment, or system settings.

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.
  • Accept complete message templates with numbered, streamable parameters.
  • Resolve cached translations automatically, retaining English for missing messages.
  • Keep the transitional *Template() methods as forwarding aliases.
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 91 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.
  • The message language and shared catalog configuration.

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 110 of file glogger.h.

◆ GLogger() [2/2]

GLogger::GLogger ( )
inline

This constructor leaves verbosity/debug settings at their defaults and resolves the language from environment or system settings. It is useful before GOptions 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.

Definition at line 130 of file glogger.h.

◆ ~GLogger()

GLogger::~GLogger ( )

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

Definition at line 3 of file glogger.cc.

Member Function Documentation

◆ critical()

template<typename... Args>
void GLogger::critical ( std::string_view message,
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
messageComplete message template, using the placeholder rules of info().
argsValues referenced by the numbered placeholders.

Definition at line 280 of file glogger.h.

◆ criticalTemplate()

template<typename... Args>
void GLogger::criticalTemplate ( std::string_view message,
Args &&... args ) const
inline

Definition at line 323 of file glogger.h.

◆ debug()

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

This method formats a complete message using the placeholder rules of info(), then prints the 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.
messageComplete message template.
argsValues referenced by the numbered placeholders.
Note
Debug output is suppressed entirely when debug_level == 0.

Definition at line 154 of file glogger.h.

◆ debugTemplate()

template<typename... Args>
void GLogger::debugTemplate ( debug_type type,
std::string_view message,
Args &&... args ) const
inline

Definition at line 305 of file glogger.h.

◆ error()

template<typename... Args>
void GLogger::error ( int exit_code,
std::string_view message,
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.
messageComplete message template, using the placeholder rules of info().
argsValues referenced by the numbered placeholders.
Note
This function is marked [[noreturn]] because it always terminates the process.

Definition at line 261 of file glogger.h.

◆ errorTemplate()

template<typename... Args>
void GLogger::errorTemplate ( int exit_code,
std::string_view message,
Args &&... args ) const
inline

Definition at line 317 of file glogger.h.

◆ get_class_name()

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

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 335 of file glogger.h.

◆ get_language()

const std::string & GLogger::get_language ( ) const
inlinenodiscard

Definition at line 338 of file glogger.h.

◆ info() [1/2]

template<typename... Args>
void GLogger::info ( int level,
std::string_view message,
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).

Placeholders %1 through %99 identify arguments by their one-based position. They may be reordered or repeated; each supplied argument must appear at least once. %% emits a literal percent sign. Other percent signs are literal. Inserted values are never parsed as templates. Each argument is converted once using its own std::ostringstream and normal stream formatting. All logging categories share these placeholder rules. Catalog lookup precedes parameter substitution; untranslated messages retain their English templates. Language selection never changes numeric formatting.

Filtering happens before formatting; C++ still evaluates argument expressions before the call. Dynamic or already-formatted text should be logged as a value: info("%1", text).

Template Parameters
ArgsParameter types with stream insertion support (at most 99 arguments).
Parameters
levelThe info importance/detail level (0, 1, or 2).
messageComplete message template.
argsValues referenced by the numbered placeholders.
Exceptions
std::invalid_argumentIf an emitted template references an unavailable/invalid argument or leaves a supplied argument unused. A suppressed message is not validated or formatted.
(processtermination) If level is not 0, 1, or 2, this method prints a fatal error and terminates the process with goptions::EC_WRONG_VERBOSITY_LEVEL.

Definition at line 202 of file glogger.h.

◆ info() [2/2]

template<typename Message, typename... Args>
requires std::is_convertible_v<Message, std::string_view>
void GLogger::info ( Message && message,
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
messageComplete message template.
argsValues referenced by the numbered placeholders.

Definition at line 221 of file glogger.h.

◆ infoTemplate() [1/2]

template<typename... Args>
void GLogger::infoTemplate ( int level,
std::string_view message,
Args &&... args ) const
inline
Parameters
levelInfo verbosity level (0, 1, or 2).
messageComplete message template.
argsValues referenced by the numbered placeholders.

Definition at line 292 of file glogger.h.

◆ infoTemplate() [2/2]

template<typename Message, typename... Args>
requires std::is_convertible_v<Message, std::string_view>
void GLogger::infoTemplate ( Message && message,
Args &&... args ) const
inline

Definition at line 299 of file glogger.h.

◆ warning()

template<typename... Args>
void GLogger::warning ( std::string_view message,
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
messageComplete message template, using the placeholder rules of info().
argsValues referenced by the numbered placeholders.

This method does not consult verbosity or debug levels.

Definition at line 238 of file glogger.h.

◆ warningTemplate()

template<typename... Args>
void GLogger::warningTemplate ( std::string_view message,
Args &&... args ) const
inline

Definition at line 311 of file glogger.h.


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