8#include "G4UIsession.hh"
27#if defined(__clang__) || defined(__GNUC__)
28#define FUNCTION_NAME std::string(__PRETTY_FUNCTION__) + std::string(" > ")
29#elif defined(_MSC_VER)
30#define FUNCTION_NAME __FUNCSIG__ + std::string(" > ")
32#define FUNCTION_NAME __func__ + std::string(" > ")
44#define SFUNCTION_NAME __func__ + std::string(" > ")
102 explicit GLogger(
const std::shared_ptr<GOptions>& gopts,
const std::string& cname,
const std::string& lname =
"")
103 : class_name(cname), logger_name(lname), log_counter{0} {
105 verbosity_level = gopts->getVerbosityFor(logger_name);
106 debug_level = gopts->getDebugFor(logger_name);
150 template <
typename... Args>
152 if (debug_level == 0)
return;
154 std::ostringstream oss;
155 (oss << ... << std::forward<Args>(args));
159 G4cout <<
KCYN << header_string() <<
"DEBUG: " << oss.str() <<
RST << G4endl;
162 G4cout <<
KCYN << header_string() <<
"DEBUG: " <<
166 G4cout <<
KCYN << header_string() <<
"DEBUG: " <<
187 template <
typename... Args>
188 void info(
int level, Args&&... args)
const {
190 if (level != 0 && level != 1 && level != 2) {
191 G4cerr <<
FATALERRORL << header_string() <<
GWARNING <<
" Invalid verbosity level requested: " << level <<
197 if (level == 0 || (level == 1 && verbosity_level > 0) || (level == 2 && verbosity_level > 1)) {
198 std::ostringstream oss;
199 (oss << ... << std::forward<Args>(args));
200 G4cout << header_string() <<
"INFO L" << level <<
": " << oss.str() << G4endl;
213 template <
typename... Args>
214 void info(Args&&... args)
const {
info(0, std::forward<Args>(args)...); }
227 template <
typename... Args>
229 std::ostringstream oss;
230 (oss << ... << std::forward<Args>(args));
249 template <
typename... Args>
250 [[noreturn]]
void error(
int exit_code, Args&&... args)
const {
251 std::ostringstream oss;
252 (oss << ... << std::forward<Args>(args));
254 G4cerr <<
FATALERRORL << header_string() <<
KRED <<
"Exit Code: " << exit_code <<
RST << G4endl;
255 std::exit(exit_code);
267 template <
typename... Args>
269 std::ostringstream oss;
270 (oss << ... << std::forward<Args>(args));
271 G4cout <<
KBOLD << header_string() <<
RST << oss.str() << G4endl;
285 std::string class_name;
286 std::string logger_name;
288 int verbosity_level{};
291 mutable std::atomic<int> log_counter{};
304 [[nodiscard]] std::string header_string()
const {
306 return " [ " + logger_name +
" - " + std::to_string(log_counter.load()) +
" ] ";
Handles structured logging with verbosity and debug levels.
void warning(Args &&... args) const
Logs a warning message.
GLogger(const std::shared_ptr< GOptions > &gopts, const std::string &cname, const std::string &lname="")
Constructs a GLogger instance and resolves its runtime configuration.
void debug(debug_type type, Args &&... args) const
Logs a debug message if the debug level is nonzero.
GLogger()=default
Default constructor.
void info(Args &&... args) const
Convenience overload of info() that defaults to level 0.
std::string get_class_name() const
Returns the caller-provided class name associated with this logger instance.
void critical(Args &&... args) const
Logs a critical message.
void info(int level, Args &&... args) const
Logs an informational message, optionally gated by verbosity level.
void error(int exit_code, Args &&... args) const
Logs an error message and terminates the process.
debug_type
Classifies debug messages by intent.
#define EC_WRONG_VERBOSITY_LEVEL