From 05c47ab65e73b16887b7c7a1eb31acf6d364ef41 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 20 Mar 2026 23:48:32 +0000 Subject: Add logging :-o Adds virtual log function, real implementation writes to syslog. Test implementation writes to BOOST_TEST_MESSAGE, perf implementation discards. Replaces existing prints to stderr and adds logs to all key points. --- src/ingestor.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/ingestor.cpp') diff --git a/src/ingestor.cpp b/src/ingestor.cpp index 1de9ab9..fb592d7 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -109,8 +109,9 @@ namespace WebStat { } void - Ingestor::terminate(int) + Ingestor::terminate(int sigNo) { + log(LOG_NOTICE, "Caught sig %d, terminating", sigNo); terminated = true; curl_multi_wakeup(curl.get()); } @@ -154,7 +155,7 @@ namespace WebStat { } else { curlOperations.erase(msg->easy_handle); - std::println(std::cerr, "Failed to lookup CurlOperation"); + log(LOG_WARNING, "Failed to lookup CurlOperation"); } } } @@ -204,7 +205,8 @@ namespace WebStat { ingestLogLines(dbpool->get().get(), queuedLines); queuedLines.clear(); } - catch (const std::exception &) { + catch (const std::exception & excp) { + log(LOG_ERR, "Unhandled exception: %s, clearing known entity list", excp.what()); existingEntities.clear(); } } @@ -234,8 +236,12 @@ namespace WebStat { DB::TransactionScope dbtx {*dbconn}; const auto uninsertableLine = ToEntity {}(line); storeEntities(dbconn, {uninsertableLine}); + log(LOG_NOTICE, + "Failed to store parsed line and/or associated entties, but did store raw line, %u:%s", + std::get(uninsertableLine), line.c_str()); } - catch (const std::exception &) { + catch (const std::exception & excp) { + log(LOG_NOTICE, "Failed to store line in any form, DB connection lost? %s", excp.what()); throw originalError; } } @@ -243,6 +249,8 @@ namespace WebStat { else { linesDiscarded++; const auto unparsableLine = ToEntity {}(line); + log(LOG_NOTICE, "Failed to parse line, this is a bug: %u:%s", std::get(unparsableLine), + line.c_str()); storeEntities(dbconn, {unparsableLine}); } } @@ -263,10 +271,13 @@ namespace WebStat { if (fflush(parked.get()) == 0) { linesParked += queuedLines.size(); queuedLines.clear(); + return; } - else { - std::filesystem::remove(path); - } + std::filesystem::remove(path); + } + log(LOG_ERR, "Failed to park %zu queued lines:", queuedLines.size()); + for (const auto & line : queuedLines) { + log(LOG_ERR, "\t%.*s", static_cast(line.length()), line.data()); } } @@ -280,7 +291,8 @@ namespace WebStat { job.currentRun->get(); job.lastRun = now; } - catch (const std::exception &) { + catch (const std::exception & excp) { + log(LOG_ERR, "Job run failed: %s", excp.what()); // Error, retry in half the frequency job.lastRun = now - (freq / 2); } -- cgit v1.3