From 4b1b0623887c24f45257c409ce332af9b765b50d Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 30 Sep 2018 14:33:54 +0300 Subject: [PATCH] Enable debug logs --- CMakeLists.txt | 9 +++++++-- cmake/nheko.h | 6 ++++++ cmake/version.h | 5 ----- src/Logging.cpp | 7 +++++++ src/Olm.cpp | 36 +++++++++++++++++------------------ src/UserSettingsPage.cpp | 2 +- src/main.cpp | 2 +- src/timeline/TimelineView.cpp | 17 ++++++++--------- src/ui/InfoMessage.cpp | 2 +- 9 files changed, 49 insertions(+), 37 deletions(-) create mode 100644 cmake/nheko.h delete mode 100644 cmake/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e5aa8952..45134632 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,12 @@ else(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES)) message("Build type set to '${CMAKE_BUILD_TYPE}'") endif(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES)) +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + set(SPDLOG_DEBUG_ON true) +else() + set(SPDLOG_DEBUG_ON false) +endif() + find_program(GIT git) if(GIT) execute_process( @@ -143,7 +149,7 @@ message(STATUS "Version: ${PROJECT_VERSION}") cmake_host_system_information(RESULT BUILD_HOST QUERY HOSTNAME) set(BUILD_USER $ENV{USER}) -configure_file(cmake/version.h config/version.h) +configure_file(cmake/nheko.h config/nheko.h) # @@ -274,7 +280,6 @@ endif() include_directories(SYSTEM ${TWEENY_INCLUDE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/src) -include_directories(${CMAKE_CURRENT_BINARY_DIR}/config) include_directories(${Boost_INCLUDE_DIRS}) qt5_wrap_cpp(MOC_HEADERS diff --git a/cmake/nheko.h b/cmake/nheko.h new file mode 100644 index 00000000..bf1a54fe --- /dev/null +++ b/cmake/nheko.h @@ -0,0 +1,6 @@ +namespace nheko { +constexpr auto version = "${PROJECT_VERSION}"; +constexpr auto build_user = "${BUILD_USER}@${BUILD_HOST}"; +constexpr auto build_os = "${CMAKE_HOST_SYSTEM_NAME}"; +constexpr auto enable_debug_log = ${SPDLOG_DEBUG_ON}; +} diff --git a/cmake/version.h b/cmake/version.h deleted file mode 100644 index 204bc895..00000000 --- a/cmake/version.h +++ /dev/null @@ -1,5 +0,0 @@ -namespace nheko { -static constexpr const char *version = "${PROJECT_VERSION}"; -static constexpr const char *build_user = "${BUILD_USER}@${BUILD_HOST}"; -static constexpr const char *build_os = "${CMAKE_HOST_SYSTEM_NAME}"; -} diff --git a/src/Logging.cpp b/src/Logging.cpp index 298949cf..686274d8 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -1,4 +1,5 @@ #include "Logging.h" +#include "config/nheko.h" #include "spdlog/sinks/rotating_file_sink.h" #include "spdlog/sinks/stdout_color_sinks.h" @@ -32,6 +33,12 @@ init(const std::string &file_path) db_logger = std::make_shared("db", std::begin(sinks), std::end(sinks)); crypto_logger = std::make_shared("crypto", std::begin(sinks), std::end(sinks)); + + if (nheko::enable_debug_log) { + db_logger->set_level(spdlog::level::trace); + ui_logger->set_level(spdlog::level::trace); + crypto_logger->set_level(spdlog::level::trace); + } } std::shared_ptr diff --git a/src/Olm.cpp b/src/Olm.cpp index dd8a8fbe..c1598570 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -92,7 +92,7 @@ handle_olm_message(const OlmMessage &msg) auto payload = try_olm_decryption(msg.sender_key, cipher.second); if (!payload.is_null()) { - nhlog::crypto()->info("decrypted olm payload: {}", payload.dump(2)); + nhlog::crypto()->debug("decrypted olm payload: {}", payload.dump(2)); create_inbound_megolm_session(msg.sender, msg.sender_key, payload); return; } @@ -146,7 +146,7 @@ handle_pre_key_olm_message(const std::string &sender, } auto plaintext = json::parse(std::string((char *)output.data(), output.size())); - nhlog::crypto()->info("decrypted message: \n {}", plaintext.dump(2)); + nhlog::crypto()->debug("decrypted message: \n {}", plaintext.dump(2)); try { cache::client()->saveOlmSession(sender_key, std::move(inbound_session)); @@ -206,11 +206,11 @@ try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCip text = olm::client()->decrypt_message(session->get(), msg.type, msg.body); cache::client()->saveOlmSession(id, std::move(session.value())); } catch (const mtx::crypto::olm_exception &e) { - nhlog::crypto()->info("failed to decrypt olm message ({}, {}) with {}: {}", - msg.type, - sender_key, - id, - e.what()); + nhlog::crypto()->debug("failed to decrypt olm message ({}, {}) with {}: {}", + msg.type, + sender_key, + id, + e.what()); continue; } catch (const lmdb::error &e) { nhlog::crypto()->critical("failed to save session: {}", e.what()); @@ -339,19 +339,19 @@ void handle_key_request_message(const mtx::events::msg::KeyRequest &req) { if (req.algorithm != MEGOLM_ALGO) { - nhlog::crypto()->info("ignoring key request {} with invalid algorithm: {}", - req.request_id, - req.algorithm); + nhlog::crypto()->debug("ignoring key request {} with invalid algorithm: {}", + req.request_id, + req.algorithm); return; } // Check if we were the sender of the session being requested. if (req.sender_key != olm::client()->identity_keys().curve25519) { - nhlog::crypto()->info("ignoring key request {} because we were not the sender: " - "\nrequested({}) ours({})", - req.request_id, - req.sender_key, - olm::client()->identity_keys().curve25519); + nhlog::crypto()->debug("ignoring key request {} because we were not the sender: " + "\nrequested({}) ours({})", + req.request_id, + req.sender_key, + olm::client()->identity_keys().curve25519); return; } @@ -380,7 +380,7 @@ handle_key_request_message(const mtx::events::msg::KeyRequest &req) } if (!utils::respondsToKeyRequests(req.room_id)) { - nhlog::crypto()->info("ignoring all key requests for room {}", req.room_id); + nhlog::crypto()->debug("ignoring all key requests for room {}", req.room_id); return; } @@ -433,7 +433,7 @@ send_megolm_key_to_device(const std::string &user_id, if ((device_keys.find(curveKey) == device_keys.end()) || (device_keys.find(edKey) == device_keys.end())) { - nhlog::net()->info("ignoring malformed keys for device {}", device_id); + nhlog::net()->debug("ignoring malformed keys for device {}", device_id); return; } @@ -499,7 +499,7 @@ send_megolm_key_to_device(const std::string &user_id, body["messages"][user_id] = json::object(); auto device = retrieved_devices.begin()->second; - nhlog::net()->info("{} : \n {}", device_id, device.dump(2)); + nhlog::net()->debug("{} : \n {}", device_id, device.dump(2)); json device_msg; diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index c9b9fb82..9245702e 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -34,7 +34,7 @@ #include "ui/FlatButton.h" #include "ui/ToggleButton.h" -#include "version.h" +#include "config/nheko.h" UserSettings::UserSettings() { load(); } diff --git a/src/main.cpp b/src/main.cpp index 4ceb535d..3e33c198 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,7 @@ #include "MatrixClient.h" #include "RunGuard.h" #include "Utils.h" -#include "version.h" +#include "config/nheko.h" #if defined(Q_OS_MAC) #include "emoji/MacHelper.h" diff --git a/src/timeline/TimelineView.cpp b/src/timeline/TimelineView.cpp index 07de25b6..6198b296 100644 --- a/src/timeline/TimelineView.cpp +++ b/src/timeline/TimelineView.cpp @@ -354,8 +354,7 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEventinfo("decrypted event: {}", e.event_id); - nhlog::crypto()->debug("decrypted data: \n {}", body.dump(2)); + nhlog::crypto()->debug("decrypted event: {}", e.event_id); json event_array = json::array(); event_array.push_back(body); @@ -746,7 +745,7 @@ TimelineView::sendNextPendingMessage() m.widget->markSent(); if (m.is_encrypted) { - nhlog::ui()->info("[{}] sending encrypted event", m.txn_id); + nhlog::ui()->debug("[{}] sending encrypted event", m.txn_id); prepareEncryptedMessage(std::move(m)); return; } @@ -1330,7 +1329,7 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg) return; } - nhlog::ui()->info("creating new outbound megolm session"); + nhlog::ui()->debug("creating new outbound megolm session"); // Create a new outbound megolm session. auto outbound_session = olm::client()->init_outbound_group_session(); @@ -1413,7 +1412,7 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg) if ((device_keys.find(curveKey) == device_keys.end()) || (device_keys.find(edKey) == device_keys.end())) { - nhlog::net()->info( + nhlog::net()->debug( "ignoring malformed keys for device {}", device_id.get()); continue; @@ -1512,15 +1511,15 @@ TimelineView::handleClaimedKeys(std::shared_ptr keeper, return; } - nhlog::net()->info("claimed keys for {}", user_id); + nhlog::net()->debug("claimed keys for {}", user_id); if (res.one_time_keys.size() == 0) { - nhlog::net()->info("no one-time keys found for user_id: {}", user_id); + nhlog::net()->debug("no one-time keys found for user_id: {}", user_id); return; } if (res.one_time_keys.find(user_id) == res.one_time_keys.end()) { - nhlog::net()->info("no one-time keys found for user_id: {}", user_id); + nhlog::net()->debug("no one-time keys found for user_id: {}", user_id); return; } @@ -1532,7 +1531,7 @@ TimelineView::handleClaimedKeys(std::shared_ptr keeper, for (const auto &rd : retrieved_devices) { const auto device_id = rd.first; - nhlog::net()->info("{} : \n {}", device_id, rd.second.dump(2)); + nhlog::net()->debug("{} : \n {}", device_id, rd.second.dump(2)); // TODO: Verify signatures auto otk = rd.second.begin()->at("key"); diff --git a/src/ui/InfoMessage.cpp b/src/ui/InfoMessage.cpp index e107b18f..e9de20cc 100644 --- a/src/ui/InfoMessage.cpp +++ b/src/ui/InfoMessage.cpp @@ -1,5 +1,5 @@ -#include "Config.h" #include "InfoMessage.h" +#include "Config.h" #include #include