#include "clickhouse/client.h" #include "spdlog/spdlog.h" #include #include #include #include #include #include "processing_utils.hpp" void process_directory(const std::string& dir_path, std::shared_ptr client, const std::string& target_user_id, bool all) { if (all) { for (auto& entry : std::filesystem::directory_iterator(dir_path)) { if (!entry.is_regular_file()) continue; std::string filename = entry.path().filename().string(); if (filename == "latest.log") continue; if (filename.ends_with(".log") || filename.ends_with(".log.gz")) { processing_utils::process_to_eof(entry.path().string(), client, target_user_id); } } } // Second pass: always follow latest.log std::filesystem::path latest_path = std::filesystem::path(dir_path) / "latest.log"; if (std::filesystem::exists(latest_path) && std::filesystem::is_regular_file(latest_path)) { processing_utils::process_blocking(latest_path.string(), client, target_user_id); } else { spdlog::warn("latest.log not found in {}", dir_path); } } int main (int argc, char *argv[]) { auto config = toml::parse_file("config.toml"); bool ingest_all_logs = config["all"].value_or(false); std::string user_id = config["user_id"].value_or("kid"); std::string log_path = config["minecraft"]["logs_path"].value_or(""); if(log_path.empty()) throw std::runtime_error("your dumbass can't put in a path"); std::string clickhouse_username = config["clickhouse"]["username"].value_or(""); std::string clickouse_password = config["clickhouse"]["password"].value_or(""); std::string clickhouse_db = config["clickhouse"]["db"].value_or(""); std::string clickhouse_host = config["clickhouse"]["host"].value_or(""); uint clickhouse_port = config["clickhouse"]["port"].value_or(9000); if(clickhouse_username.empty() || clickouse_password.empty() || clickhouse_db.empty() || clickhouse_host.empty()) throw std::runtime_error("put the creds in the right place idiot"); spdlog::info("Logging is functional"); std::shared_ptr shared_client = std::make_shared(clickhouse::ClientOptions().SetPassword(clickouse_password).SetDefaultDatabase(clickhouse_db).SetUser(clickhouse_username).SetHost(clickhouse_host).SetPort(clickhouse_port)); spdlog::info("Server connection: {}", shared_client->GetServerInfo().display_name); spdlog::info("runnign on given path: {}", log_path); process_directory(log_path, shared_client, user_id, ingest_all_logs); return 0; }