Handles structured logging with verbosity and debug levels.
More...
#include <glogger.h>
|
| | 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.
|
| |
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.
◆ 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
-
| gopts | Shared pointer to the GOptions instance used for verbosity/debug lookup. |
| cname | Caller-provided class name (informational; currently not used for filtering). |
| lname | The logger name (subsystem identifier). This is used as the lookup key in GOptions. |
Definition at line 102 of file glogger.h.
◆ GLogger() [2/2]
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()
Emits a destructor-style debug message via debug() (only if debug is enabled).
Definition at line 130 of file glogger.h.
◆ 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
-
| Args | Variadic template parameters for any streamable types. |
- Parameters
-
| args | Message 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
-
| Args | Variadic template parameters representing any streamable types. |
- Parameters
-
| type | The debug message classification : NORMAL, CONSTRUCTOR, or DESTRUCTOR. |
| args | The 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
-
| Args | Variadic template parameters for any streamable types. |
- Parameters
-
| exit_code | The program exit code to return to the calling environment. |
| args | Message 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
-
| Args | Variadic template parameters for any streamable types. |
- Parameters
-
| args | Streamable 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
-
| Args | Variadic template parameters for any streamable types. |
- Parameters
-
| level | The info importance/detail level (0, 1, or 2). |
| args | Message components to log. Each argument must be stream-insertable. |
- Exceptions
-
| (process | termination) 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
-
| Args | Variadic template parameters for any streamable types. |
- Parameters
-
| args | Message 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: