|
glogging
|
The GLogger module provides structured, consistently formatted logging for the simulation runtime. It is intended to be the single place where verbosity/debug policies and log formatting rules are applied so that the rest of the codebase can emit messages without re-implementing filtering, headers, or formatting.
At a high level, a logger instance:
G4cout / G4cerr).The logger supports multiple message categories:
Many subsystems in this project derive from GLogger (or aggregate a GLogger instance) and expose runtime-configurable output control.
Verbosity affects informational messages:
Debug affects debug messages:
This module reads the following option keys from the runtime option provider:
Note: GOptions(argc,argv,...) defines these keys as global conventions so any module can participate in consistent logging without re-defining these options.
Each emitted message is prepended with a compact header that includes:
The counter is particularly useful in multi-threaded environments because it helps correlate message order even when different threads interleave output.
std::atomic<int> counter is used to produce the per-instance sequence number in a thread-safe manner.[[noreturn]] and terminates the process.Upcoming in the next release: info(), debug(), warning(), error(), and critical() accept a complete message and separate parameter values. The transitional *Template() names forward to the same methods; the former concatenating calls must be migrated.
Placeholders %1 through %99 refer to the one-based argument positions and may be reordered or repeated. Every supplied argument must be referenced. Each value is streamed once, and inserted values are never interpreted as additional placeholders. %% emits a literal percent sign; other percent signs are literal. For example, "%1%% complete" with the value 50 produces "50% complete".
An invalid, missing, or unused parameter throws std::invalid_argument before any message is emitted. Info/debug filtering happens before formatting, so suppressed messages neither stream their values nor validate their placeholders. Argument expressions are still evaluated by C++ before the call. Each parameter uses its own stream; stream manipulators do not carry over between parameters. Output categories, colors, counters, verbosity validation, and fatal exit codes follow the existing API. Catalog lookup happens before substitution; messages without translations use their English templates.
Keep the complete sentence in the template and replace each value with its numbered placeholder:
Logging a dynamic string as a value preserves percent signs in filenames or external diagnostics. Rebuild external plugins against matching GEMC headers after updating their logging calls.
Upcoming in the next release: ci/extract_messages.py extracts literal logging templates selected by translations/catalog.yaml into translations/en.yaml. English C++ remains the source of truth. Identical templates share one entry, with source locations recorded as comments. Documentation examples, tests, and messages containing only dynamic data are excluded. A separate manifest and English catalog belong to CLAS12; the tool accepts --root to select that owning repository.
extract --check fails when the generated catalog is stale. Catalog validation rejects duplicate keys, empty translations, and changed parameter positions; reordering and repetition are allowed. Translated catalogs may be partial, using English fallback. The shared Claude/Codex workflow generates language catalogs through the existing weekday cron job, with validated, resumable batches and source-commit tracking. See translations/README.md for the format, workflow commands, and scanner limits. CI validates all catalogs without agents, rejecting altered placeholders, percent escapes, and required whitespace. Missing messages report coverage and retain English fallback; agents review language accuracy.
Upcoming in the next release: language: auto selects the language without requiring a user option. An explicit -language=<code> (or YAML scalar) overrides GEMC_LANGUAGE; automatic selection then checks LC_ALL, LC_MESSAGES, and LANG, followed by native macOS/Windows settings or English. C and POSIX locales select English. it_IT.UTF-8 normalizes to it-it, with it.yaml used for messages absent from it-it.yaml. -language=en forces English. Numeric formatting is unchanged.
Meson installs catalogs in <prefix>/<datadir>/gemc/translations/gemc; CLAS12 owns a separate clas12 directory there. GEMC_TRANSLATION_PATH supplies optional colon-separated search directories. Existing plugin search paths also expose neighboring catalog installations; recognized build trees find the owning source catalogs. Regional entries precede base-language entries, then the first message in search-path order wins. Missing or invalid catalogs retain English fallback.
Matching logger configurations share an immutable GMessageCatalog cache. Invalid files produce one diagnostic per cached configuration; they cannot change fatal exit codes. Message lookup performs no filesystem access, and suppressed messages do not perform lookup or substitution. Rebuild plugins against matching headers and the glogging library. Restart to reload changed catalogs. get_language() reports the normalized requested language tag.
This example shows how a subsystem creates a logger with a configured subsystem name and emits always-on informational output.
This example shows how to emit progressively more detailed messages depending on verbosity.
This example shows debug output that appears only when debug is enabled for the logger name.