logging: address code-review feedback

- Fix a critical regression where startup errors emitted before
  geulog::configure() (bad --config path, unknown CLI flag, --version
  banner) were queued into the async deque with no running worker
  and silently dropped on exit(). detail::enqueue() now falls back to
  synchronous ::write() to stdout/stderr when the worker is inactive.
- Remove the dead TRUNK_DEBUG parse block in Reflector.cpp and the
  m_trunk_debug member in Reflector.h — all gates were already
  removed in Phase 1; only the (unread) parse remained.
- Replace the #TRUNK_DEBUG=0 comment in svxreflector.conf.in with a
  documented LOG= reference block.
- Restore the [host:port] peer identity on the ReflectorClient
  ENOTCONN debug line so sysops can still correlate failures.
- Revert sighup_handler and sigterm_handler to async-signal-safe
  ::write(STDERR_FILENO, ...) instead of calling the (mutex-taking,
  allocating) facade from signal context.
- Retag two MsgTrunk* diagnostic sites in ReflectorMsg.h from core
  to trunk to match the enclosing-class rule.
- Doc: note that argument expressions are evaluated at the call site
  before the shouldLog() gate runs, and reword the "never drops"
  claim to acknowledge rare short-write truncation.
This commit is contained in:
Audric committed 2026-04-18 21:02:42 +02:00
1 parent 9761c6147f
commit efa02459e9
9 files changed
+73 -30

No files matched your search

+15
View File
@@ -33,6 +33,7 @@ std::condition_variable g_queue_cv;
std::deque<std::string> g_queue;
bool g_stop = false; // guarded by g_queue_mu
std::thread g_worker;
std::atomic<bool> g_worker_active{false};
int subIndex(const char* sub) {
for (std::size_t i = 0; i < NUM_SUBSYSTEMS; ++i) {
@@ -95,6 +96,7 @@ void startWorker() {
g_stop = false;
}
g_worker = std::thread(workerLoop);
g_worker_active.store(true, std::memory_order_release);
}
} // anonymous namespace
@@ -118,6 +120,18 @@ void enqueue(Level lvl, const char* sub, std::string&& msg) {
line += "] ";
line += msg;
line += "\n";
if (!g_worker_active.load(std::memory_order_acquire)) {
// Worker not running (pre-configure, post-shutdown, or configure
// aborted before startWorker). Write synchronously so startup
// errors and --version output still reach the sysop. warn/error
// go to stderr; info/debug/trace to stdout (matches the
// pre-facade std::cerr / std::cout split).
int fd = (lvl >= Level::Warn) ? STDERR_FILENO : STDOUT_FILENO;
(void)::write(fd, line.data(), line.size());
return;
}
{
std::lock_guard<std::mutex> lock(g_queue_mu);
g_queue.push_back(std::move(line));
@@ -191,6 +205,7 @@ void shutdown() {
}
g_queue_cv.notify_all();
if (g_worker.joinable()) g_worker.join();
g_worker_active.store(false, std::memory_order_release);
}
bool setLevel(const std::string& sub, const std::string& lvl_s) {
+11
View File
@@ -71,6 +71,17 @@ namespace detail {
}
}
// NOTE: argument expressions passed to geulog::debug/info/... are
// evaluated at the call site BEFORE shouldLog() runs. The gate skips
// formatting (the ostringstream + concat), not evaluation. For call
// sites where argument evaluation is expensive, guard with an explicit
// shouldLog() check:
//
// if (geulog::shouldLog("trunk", geulog::Level::Debug))
// geulog::debug("trunk", expensive_rpc_call());
//
// All current call sites pass cheap member accesses, so this is only
// a concern for future migrations with non-trivial argument work.
#define _LOG_DEFINE(fnname, lvlenum) \
template <typename... Args> \
inline void fnname(const char* sub, Args&&... args) { \