diff --git a/libursa/OnDiskDataset.cpp b/libursa/OnDiskDataset.cpp index fb41635..80e3210 100644 --- a/libursa/OnDiskDataset.cpp +++ b/libursa/OnDiskDataset.cpp @@ -8,6 +8,7 @@ #include "DatabaseName.h" #include "Json.h" #include "Query.h" +#include "spdlog/fmt/ostr.h" #include "spdlog/spdlog.h" void OnDiskDataset::save() { @@ -91,6 +92,7 @@ void OnDiskDataset::execute(const Query &query, ResultWriter *out, types_to_query.emplace(ndx.index_type()); } const Query plan = query.plan(types_to_query); + spdlog::debug("PLAN: {}", plan); QueryResult result = this->query(plan, counters); if (result.is_everything()) { diff --git a/libursa/Query.cpp b/libursa/Query.cpp index 5df7c8b..262df7d 100644 --- a/libursa/Query.cpp +++ b/libursa/Query.cpp @@ -43,11 +43,11 @@ std::ostream &operator<<(std::ostream &os, const Query &query) { if (type == QueryType::AND || type == QueryType::OR || type == QueryType::MIN_OF) { if (type == QueryType::AND) { - os << "AND("; + os << "and("; } else if (type == QueryType::OR) { - os << "OR("; + os << "or("; } else if (type == QueryType::MIN_OF) { - os << "MIN_OF(" << query.as_count() << ", "; + os << "min_of(" << query.as_count() << ", "; } bool is_first = true; @@ -81,7 +81,9 @@ std::string Query::as_string_repr() const { std::string out = ""; if (value.empty()) { // Query is already after planning stage. Show low-level representation. - return fmt::format("{}:[{:06x}]", (int)ngram.itype, ngram.trigram); + // First digit is the index type and the rest is the raw trigram. + // Underscore was picked to make copying from terminal easier. + return fmt::format("{}_{:06x}", (int)ngram.itype, ngram.trigram); } // No query plan yet. Show stringlike representation. for (const auto &token : value) { diff --git a/libursa/Version.h.in b/libursa/Version.h.in index d8826cd..73203c2 100644 --- a/libursa/Version.h.in +++ b/libursa/Version.h.in @@ -9,4 +9,4 @@ constexpr std::string_view ursadb_format_version = "1.5.0"; // Project version. // Consider updating the version tag when doing PRs. constexpr std::string_view ursadb_version_string = - "@PROJECT_VERSION@+primitives"; + "@PROJECT_VERSION@+debuglogs"; diff --git a/src/NetworkService.cpp b/src/NetworkService.cpp index 7b55dfe..a30626e 100644 --- a/src/NetworkService.cpp +++ b/src/NetworkService.cpp @@ -188,12 +188,17 @@ void NetworkService::poll_frontend() { s_send(&backend, request, ZMQTRACE); } +void print_usage_and_exit() { + puts("Usage:"); + puts(" ursadb database-file [bind-address]"); + puts(" -v Enable verbose output (debug messages)"); + exit(1); +} + // Main entry point of the system! int main(int argc, char *argv[]) { if (argc < 2) { - printf("Usage:\n"); - printf(" %s database-file [bind-address]\n", argv[0]); - return 1; + print_usage_and_exit(); } spdlog::info("UrsaDB v{}", get_version_string()); @@ -202,15 +207,33 @@ int main(int argc, char *argv[]) { migrate_version(argv[1]); try { - Database db(argv[1]); - std::string bind_address = "tcp://127.0.0.1:9281"; + bool enable_debug = false; + const char *db_file = NULL; + const char *bind_address = NULL; + for (int i = 1; i < argc; i++) { + if (std::string("-v") == argv[i]) { + enable_debug = true; + } else if (db_file == NULL) { + db_file = argv[i]; // first positional arg + } else if (bind_address == NULL) { + bind_address = argv[i]; + } else { + spdlog::error("Too many positional arguments."); + } + } + + if (db_file == NULL) { + print_usage_and_exit(); + } else if (bind_address == NULL) { + bind_address = "tcp://127.0.0.1:9281"; + } - if (argc > 3) { - spdlog::error("Too many command line arguments."); - } else if (argc == 3) { - bind_address = std::string(argv[2]); + if (enable_debug) { + spdlog::set_level(spdlog::level::debug); + spdlog::debug("Debug logging enabled"); } + Database db(db_file); spdlog::info("BIND: {}", bind_address); NetworkService service(db, bind_address); service.run();