4#include <gemc/guts/gutsConventions.h>
5#include <gemc/goptions/goptions.h>
9#include "G4UIsession.hh"
32#if defined(__clang__) || defined(__GNUC__)
33#define FUNCTION_NAME std::string(__PRETTY_FUNCTION__) + std::string(" > ")
34#elif defined(_MSC_VER)
35#define FUNCTION_NAME std::string(__FUNCSIG__) + std::string(" > ")
37#define FUNCTION_NAME std::string(__func__) + std::string(" > ")
51#define SFUNCTION_NAME std::string(__func__) + std::string(" > ")
110 explicit GLogger(
const std::shared_ptr<GOptions>& gopts,
const std::string& cname,
111 const std::string& lname =
"")
112 : class_name(cname), logger_name(lname), log_counter{0}, catalog(
GMessageCatalog::load(gopts.get())) {
114 verbosity_level = gopts->getVerbosityFor(logger_name);
115 debug_level = gopts->getDebugFor(logger_name);
153 template <
typename... Args>
155 if (debug_level == 0)
return;
156 const auto text = format_message(message, std::forward<Args>(args)...);
163 G4cout <<
guts::KCYN << header_string() <<
"DEBUG: " <<
167 G4cout <<
guts::KCYN << header_string() <<
"DEBUG: " <<
201 template <
typename... Args>
202 void info(
int level, std::string_view message, Args&&... args)
const {
203 if (info_enabled(level)) {
204 const auto text = format_message(message, std::forward<Args>(args)...);
205 G4cout << header_string() <<
"INFO L" << level <<
": " << text << G4endl;
219 template <
typename Message,
typename... Args>
220 requires std::is_convertible_v<Message, std::string_view>
221 void info(Message&& message, Args&&... args)
const {
222 info(0, std::string_view(std::forward<Message>(message)), std::forward<Args>(args)...);
237 template <
typename... Args>
238 void warning(std::string_view message, Args&&... args)
const {
239 const auto text = format_message(message, std::forward<Args>(args)...);
260 template <
typename... Args>
261 [[noreturn]]
void error(
int exit_code, std::string_view message, Args&&... args)
const {
262 const auto text = format_message(message, std::forward<Args>(args)...);
266 std::exit(exit_code);
279 template <
typename... Args>
280 void critical(std::string_view message, Args&&... args)
const {
281 const auto text = format_message(message, std::forward<Args>(args)...);
291 template <
typename... Args>
292 void infoTemplate(
int level, std::string_view message, Args&&... args)
const {
293 info(level, message, std::forward<Args>(args)...);
297 template <
typename Message,
typename... Args>
298 requires std::is_convertible_v<Message, std::string_view>
300 info(0, std::string_view(std::forward<Message>(message)), std::forward<Args>(args)...);
304 template <
typename... Args>
306 debug(type, message, std::forward<Args>(args)...);
310 template <
typename... Args>
312 warning(message, std::forward<Args>(args)...);
316 template <
typename... Args>
317 [[noreturn]]
void errorTemplate(
int exit_code, std::string_view message, Args&&... args)
const {
318 error(exit_code, message, std::forward<Args>(args)...);
322 template <
typename... Args>
324 critical(message, std::forward<Args>(args)...);
338 [[nodiscard]]
const std::string&
get_language()
const {
return catalog->language(); }
341 std::string class_name;
342 std::string logger_name;
344 int verbosity_level{};
347 mutable std::atomic<int> log_counter{};
348 std::shared_ptr<const GMessageCatalog> catalog;
351 [[nodiscard]]
bool info_enabled(
int level)
const {
352 if (level != 0 && level != 1 && level != 2) {
354 <<
" Invalid verbosity level requested: " << level <<
guts::RST << G4endl;
357 return level == 0 || (level == 1 && verbosity_level > 0) || (level == 2 && verbosity_level > 1);
361 template <
typename... Args>
362 [[nodiscard]] std::string format_message(std::string_view message, Args&&... args)
const {
363 return catalog->format(message, std::forward<Args>(args)...);
377 [[nodiscard]] std::string header_string()
const {
379 return " [ " + logger_name +
" - " + std::to_string(log_counter.load()) +
" ] ";
void info(int level, std::string_view message, Args &&... args) const
Logs a complete message template, optionally gated by verbosity level.
void warningTemplate(std::string_view message, Args &&... args) const
Transitional alias for warning().
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 info(Message &&message, Args &&... args) const
Convenience overload of info() that defaults to level 0.
void criticalTemplate(std::string_view message, Args &&... args) const
Transitional alias for critical().
void debug(debug_type type, std::string_view message, Args &&... args) const
Logs a debug message if the debug level is nonzero.
void errorTemplate(int exit_code, std::string_view message, Args &&... args) const
Transitional alias for error().
void critical(std::string_view message, Args &&... args) const
Logs a critical message.
void infoTemplate(int level, std::string_view message, Args &&... args) const
Transitional alias for info(), with identical template and filtering semantics.
void error(int exit_code, std::string_view message, Args &&... args) const
Logs an error message and terminates the process.
GLogger()
Default constructor.
std::string get_class_name() const
Returns the caller-provided class name associated with this logger instance.
void infoTemplate(Message &&message, Args &&... args) const
Logs a message template at info level 0; see infoTemplate(int, std::string_view, Args&&....
void warning(std::string_view message, Args &&... args) const
Logs a warning message.
void debugTemplate(debug_type type, std::string_view message, Args &&... args) const
Transitional alias for debug().
const std::string & get_language() const
Normalized language selected from options, environment, or system settings.
Immutable, cached translations of complete English message templates.
debug_type
Classifies debug messages by intent.
constexpr int EC_WRONG_VERBOSITY_LEVEL
constexpr char FATALERRORL[]
constexpr char GWARNING[]
constexpr char DESTRUCTORLOG[]
constexpr char CONSTRUCTORLOG[]