diff --git a/CMakeLists.txt b/CMakeLists.txt index e5aa895..4513463 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 0000000..bf1a54f --- /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 204bc89..0000000 --- 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 298949c..686274d 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 dd8a8fb..c159857 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 c9b9fb8..9245702 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 4ceb535..3e33c19 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 07de25b..6198b29 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 e107b18..e9de20c 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