Improved logging

It should better indicate when and why it stops running.
Also added log about finishing processing saved data when no writer thread is used.
This commit is contained in:
Aleksei Nikiforov 2020-01-30 11:41:54 +03:00
parent 6fecac06f8
commit 8c31581728

View File

@ -58,6 +58,7 @@
int runpipes[2] = { -1, -1 };
volatile bool running = true;
volatile bool got_signal = false;
int write_thread_control_pipes[2] = { -1, -1 };
int write_thread_data_pipes[2] = { -1, -1 };
@ -108,6 +109,8 @@ static void stop_running()
static void term_handler(int sig)
{
got_signal = true;
stop_running();
}
@ -659,6 +662,8 @@ int main(int argc, char **argv)
try
{
Logger::write("Initializing");
clickhouse::ClientOptions client_options;
std::string table_name = "AuditData";
@ -965,8 +970,12 @@ int main(int argc, char **argv)
}
}
}
Logger::write("Wrote all saved data to DB");
}
Logger::write("Initializing data processing");
std::unique_ptr<std::thread, void(*)(std::thread*)> writer_thread(
use_writer_thread ? new std::thread(
writer_thread_function,
@ -1015,6 +1024,8 @@ int main(int argc, char **argv)
pollfds[0].fd = STDIN_FILENO;
pollfds[1].fd = runpipes[0];
Logger::write("Initialization finished");
while (running)
{
pollfds[0].events = POLLIN | POLLHUP;
@ -1057,9 +1068,12 @@ int main(int argc, char **argv)
else if ((pollfds[0].revents & POLLHUP) || (pollfds[0].revents & POLLERR))
{
// stdin closed, no more data, finish running
Logger::write("Stdin hangup or error, stopping");
running = false;
}
}
Logger::write("Finishing running, signal received: %s", got_signal ? "true" : "false");
}
catch (const std::exception &e)
{
@ -1072,5 +1086,14 @@ int main(int argc, char **argv)
return -1;
}
try
{
Logger::write("Finished running");
}
catch (...)
{
// ignore exceptions here
}
return 0;
}