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 * init_client () noexcept
 Start the client backend and the combi / traceback loggers once.
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 111 of file EonLogger.h.

111 {
112 static std::atomic<quill::Logger *> cached_logger{nullptr};
113 if (quill::Logger *l = cached_logger.load(std::memory_order_relaxed)) {
114 return l;
115 }
116
117 if (auto *logger = quill::Frontend::get_logger(
118 std::string(detail::kDefaultLoggerName))) {
119 cached_logger.store(logger, std::memory_order_relaxed);
120 return logger;
121 }
122
123 // Fallback for Python bindings/tests that didn't run ClientEON's main()
124 static quill::Logger *fallback = []() -> quill::Logger * {
125 try {
126 quill::Backend::start();
127 } catch (...) {
128 } // Ignore if backend already started
129
130 try {
131 auto console_sink =
132 quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
133 "fallback_console");
134 return quill::Frontend::create_or_get_logger(
135 "combi", std::move(console_sink),
136 quill::PatternFormatterOptions{"%(message)"},
137 quill::ClockSourceType::System);
138 } catch (...) {
139 return nullptr;
140 }
141 }();
142 if (fallback)
143 cached_logger.store(fallback, std::memory_order_relaxed);
144 return fallback;
145}
constexpr std::string_view kDefaultLoggerName
Definition EonLogger.h:33

◆ 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 178 of file EonLogger.h.

179 {
180 // If the logger already exists, return it immediately.
181 // Quill strictly checks configuration matches on recreation and throws if
182 // PatternFormatterOptions differ, which crashes instances (like
183 // Dimer/Optimizers) that are created multiple times in loops (e.g., NEB).
184 if (auto *existing = quill::Frontend::get_logger(std::string(name))) {
185 return existing;
186 }
187 static std::mutex file_logger_mutex;
188 std::lock_guard<std::mutex> lock(file_logger_mutex);
189 if (auto *existing = quill::Frontend::get_logger(std::string(name))) {
190 return existing;
191 }
192
193 try {
194 // Durable absolute path: optimizers open "_lbfgs.log" etc. under CWD.
195 // Job integration fixtures chdir into /tmp/eon_test_job_* then delete that
196 // tree when the case ends, while Quill's process-lifetime FileSink still
197 // flushes — "fopen failed after 3 attempts". Keep logs under a stable
198 // temp subdir instead of the disposable workdir.
199 namespace fs = std::filesystem;
200 fs::path path{std::string(filename)};
201 if (!path.is_absolute()) {
202 static const fs::path log_dir = [] {
203 fs::path d = fs::temp_directory_path() / "eon_logs";
204 std::error_code ec;
205 fs::create_directories(d, ec);
206 return d;
207 }();
208 path = log_dir / path.filename();
209 }
210 quill::FileSinkConfig cfg;
211 cfg.set_open_mode('w');
212 auto file_sink = quill::Frontend::create_or_get_sink<quill::FileSink>(
213 path.string(), cfg);
214 return quill::Frontend::create_or_get_logger(
215 std::string(name), std::move(file_sink),
216 quill::PatternFormatterOptions{std::string(pattern)},
217 quill::ClockSourceType::System);
218 } catch (...) {
219 return get(); // Fallback to default combi logger if creation fails
220 }
221}
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition EonLogger.h:111

◆ init_client()

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

Start the client backend and the combi / traceback loggers once.

Not called from process load. Help, version, and feature flags return before this. Tests that already registered "combi" are left alone.

Definition at line 43 of file EonLogger.h.

43 {
44 static std::once_flag once;
45 std::call_once(once, [] {
46 if (quill::Frontend::get_logger(std::string(detail::kDefaultLoggerName))) {
47 return;
48 }
49 try {
50 quill::BackendOptions backend_options;
51 // The backend thread sleeps this long when its queues are empty. At
52 // 10 us it woke about 13,000 times a second beside the force loop;
53 // at 1 ms a line reaches its sink at most 1 ms late. Order is kept
54 // either way, and Backend::stop and flush_log drain the queues.
55 backend_options.sleep_duration = detail::kBackendSleep;
56 backend_options.transit_event_buffer_initial_capacity = 2048;
57 backend_options.log_timestamp_ordering_grace_period =
58 std::chrono::microseconds{0};
59 backend_options.sink_min_flush_interval = std::chrono::milliseconds{100};
60 backend_options.check_printable_char = {};
61 try {
62 quill::Backend::start(backend_options);
63 } catch (...) {
64 }
65 auto console_sink =
66 quill::Frontend::create_or_get_sink<quill::ConsoleSink>("console");
67 auto file_sink = quill::Frontend::create_or_get_sink<quill::FileSink>(
68 "client_quill.log",
69 []() {
70 quill::FileSinkConfig cfg;
71 cfg.set_open_mode('w');
72 return cfg;
73 }(),
74 quill::FileEventNotifier{});
75 auto *logger = quill::Frontend::create_or_get_logger(
76 "combi", {std::move(console_sink), std::move(file_sink)},
77 quill::PatternFormatterOptions{"%(message)"},
78 quill::ClockSourceType::System);
79 logger->set_log_level(quill::LogLevel::TraceL3);
80 auto trace_csink =
81 quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
82 "trace_console");
83 auto trace_fsink = quill::Frontend::create_or_get_sink<quill::FileSink>(
84 "client_traceback.log",
85 []() {
86 quill::FileSinkConfig cfg;
87 cfg.set_open_mode('w');
88 return cfg;
89 }(),
90 quill::FileEventNotifier{});
91 quill::Frontend::create_or_get_logger(
92 "_traceback", {std::move(trace_csink), std::move(trace_fsink)},
93 quill::PatternFormatterOptions{
94 " [%(log_level)] [%(source_location)] [%(caller_function)] \n "
95 "%(message)\n[end %(log_level)]"},
96 quill::ClockSourceType::System);
97 } catch (...) {
98 }
99 });
100 return quill::Frontend::get_logger(std::string(detail::kDefaultLoggerName));
101}
constexpr std::chrono::milliseconds kBackendSleep
Idle sleep of the client's logging backend thread.
Definition EonLogger.h:36

◆ 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 155 of file EonLogger.h.

155 {
156 static std::atomic<quill::Logger *> cached{nullptr};
157 if (quill::Logger *l = cached.load(std::memory_order_relaxed)) {
158 return l;
159 }
160 if (auto *logger = quill::Frontend::get_logger(
161 std::string(detail::kTracebackLoggerName))) {
162 cached.store(logger, std::memory_order_relaxed);
163 return logger;
164 }
165 return nullptr;
166}
constexpr std::string_view kTracebackLoggerName
Definition EonLogger.h:34