Loading...
Searching...
No Matches
eonc::log Namespace Reference

Namespaces

namespace  detail

Classes

struct  Scoped
 RAII helper for class-scoped logging. More...
struct  FileScoped
 RAII helper for file-based logging in a class. More...

Functions

quill::Logger * get () noexcept
 Get or create the default "combi" logger.
quill::Logger * traceback () noexcept
 Get or create the "_traceback" logger for traceback logging.
quill::Logger * get_file (std::string_view name, std::string_view filename, std::string_view pattern="%(message)")
 Get or create a named logger with a file sink.

Function Documentation

◆ get()

quill::Logger * eonc::log::get ( )
inlinenodiscardnoexcept

Get or create the default "combi" logger.

This is the primary logger used throughout eOn. Returns a raw pointer (quill's API) that is valid for the lifetime of the program.

Usage: auto* log = eonc::log::get(); QUILL_LOG_INFO(log, "message");

Definition at line 44 of file EonLogger.h.

44 {
45 static std::atomic<quill::Logger *> cached_logger{nullptr};
46 if (quill::Logger *l = cached_logger.load(std::memory_order_relaxed)) {
47 return l;
48 }
49
50 if (auto *logger = quill::Frontend::get_logger(
51 std::string(detail::kDefaultLoggerName))) {
52 cached_logger.store(logger, std::memory_order_relaxed);
53 return logger;
54 }
55
56 // Fallback for Python bindings/tests that didn't run ClientEON's main()
57 static quill::Logger *fallback = []() -> quill::Logger * {
58 try {
59 quill::Backend::start();
60 } catch (...) {
61 } // Ignore if backend already started
62
63 try {
64 auto console_sink =
65 quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
66 "fallback_console");
67 return quill::Frontend::create_or_get_logger(
68 "combi", std::move(console_sink),
69 quill::PatternFormatterOptions{"%(message)"},
70 quill::ClockSourceType::System);
71 } catch (...) {
72 return nullptr;
73 }
74 }();
75 if (fallback)
76 cached_logger.store(fallback, std::memory_order_relaxed);
77 return fallback;
78}
constexpr std::string_view kDefaultLoggerName
Definition EonLogger.h:32

◆ get_file()

quill::Logger * eonc::log::get_file ( std::string_view name,
std::string_view filename,
std::string_view pattern = "%(message)" )
inlinenodiscard

Get or create a named logger with a file sink.

Creates a logger that writes to the specified file with the given pattern. If the logger already exists, returns the existing instance.

Parameters
nameLogger name (must be unique)
filenameOutput file path
patternQuill format pattern (default: "%(message)")
Returns
Raw pointer to the logger (valid for program lifetime)

Definition at line 111 of file EonLogger.h.

112 {
113 // If the logger already exists, return it immediately.
114 // Quill strictly checks configuration matches on recreation and throws if
115 // PatternFormatterOptions differ, which crashes instances (like
116 // Dimer/Optimizers) that are created multiple times in loops (e.g., NEB).
117 if (auto *existing = quill::Frontend::get_logger(std::string(name))) {
118 return existing;
119 }
120 static std::mutex file_logger_mutex;
121 std::lock_guard<std::mutex> lock(file_logger_mutex);
122 if (auto *existing = quill::Frontend::get_logger(std::string(name))) {
123 return existing;
124 }
125
126 try {
127 // Durable absolute path: optimizers open "_lbfgs.log" etc. under CWD.
128 // Job integration fixtures chdir into /tmp/eon_test_job_* then delete that
129 // tree when the case ends, while Quill's process-lifetime FileSink still
130 // flushes — "fopen failed after 3 attempts". Keep logs under a stable
131 // temp subdir instead of the disposable workdir.
132 namespace fs = std::filesystem;
133 fs::path path{std::string(filename)};
134 if (!path.is_absolute()) {
135 static const fs::path log_dir = [] {
136 fs::path d = fs::temp_directory_path() / "eon_logs";
137 std::error_code ec;
138 fs::create_directories(d, ec);
139 return d;
140 }();
141 path = log_dir / path.filename();
142 }
143 quill::FileSinkConfig cfg;
144 cfg.set_open_mode('w');
145 auto file_sink = quill::Frontend::create_or_get_sink<quill::FileSink>(
146 path.string(), cfg);
147 return quill::Frontend::create_or_get_logger(
148 std::string(name), std::move(file_sink),
149 quill::PatternFormatterOptions{std::string(pattern)},
150 quill::ClockSourceType::System);
151 } catch (...) {
152 return get(); // Fallback to default combi logger if creation fails
153 }
154}
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition EonLogger.h:44

◆ traceback()

quill::Logger * eonc::log::traceback ( )
inlinenodiscardnoexcept

Get or create the "_traceback" logger for traceback logging.

This logger is used for detailed traceback and debugging information. Returns a raw pointer (quill's API) valid for the lifetime of the program.

Usage: auto* log = eonc::log::traceback(); QUILL_LOG_INFO(log, "traceback message");

Definition at line 88 of file EonLogger.h.

88 {
89 static std::atomic<quill::Logger *> cached{nullptr};
90 if (quill::Logger *l = cached.load(std::memory_order_relaxed)) {
91 return l;
92 }
93 if (auto *logger = quill::Frontend::get_logger(
94 std::string(detail::kTracebackLoggerName))) {
95 cached.store(logger, std::memory_order_relaxed);
96 return logger;
97 }
98 return nullptr;
99}
constexpr std::string_view kTracebackLoggerName
Definition EonLogger.h:33