summaryrefslogtreecommitdiff
path: root/src/ingestor.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-03-20 23:48:32 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-03-20 23:48:32 +0000
commit05c47ab65e73b16887b7c7a1eb31acf6d364ef41 (patch)
tree837a65e5460154a8c00c91519a8ea313445ad1dd /src/ingestor.cpp
parent0f5a0a8e2d43774288d4d6ea747278ca6e085a2a (diff)
downloadwebstat-05c47ab65e73b16887b7c7a1eb31acf6d364ef41.tar.bz2
webstat-05c47ab65e73b16887b7c7a1eb31acf6d364ef41.tar.xz
webstat-05c47ab65e73b16887b7c7a1eb31acf6d364ef41.zip
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.
Diffstat (limited to 'src/ingestor.cpp')
-rw-r--r--src/ingestor.cpp28
1 files changed, 20 insertions, 8 deletions
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<EntityType::UninsertableLine> {}(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<Crc32Value>(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<EntityType::UnparsableLine> {}(line);
+ log(LOG_NOTICE, "Failed to parse line, this is a bug: %u:%s", std::get<Crc32Value>(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<int>(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);
}