Enable debug logs

This commit is contained in:
Konstantinos Sideris 2018-09-30 14:33:54 +03:00
parent 8f89ad15f7
commit 4b1b062388
9 changed files with 49 additions and 37 deletions

View file

@ -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

6
cmake/nheko.h Normal file
View file

@ -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};
}

View file

@ -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}";
}

View file

@ -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<spdlog::logger>("db", std::begin(sinks), std::end(sinks));
crypto_logger =
std::make_shared<spdlog::logger>("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<spdlog::logger>

View file

@ -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,7 +206,7 @@ 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 {}: {}",
nhlog::crypto()->debug("failed to decrypt olm message ({}, {}) with {}: {}",
msg.type,
sender_key,
id,
@ -339,7 +339,7 @@ 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: {}",
nhlog::crypto()->debug("ignoring key request {} with invalid algorithm: {}",
req.request_id,
req.algorithm);
return;
@ -347,7 +347,7 @@ handle_key_request_message(const mtx::events::msg::KeyRequest &req)
// 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: "
nhlog::crypto()->debug("ignoring key request {} because we were not the sender: "
"\nrequested({}) ours({})",
req.request_id,
req.sender_key,
@ -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;

View file

@ -34,7 +34,7 @@
#include "ui/FlatButton.h"
#include "ui/ToggleButton.h"
#include "version.h"
#include "config/nheko.h"
UserSettings::UserSettings() { load(); }

View file

@ -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"

View file

@ -354,8 +354,7 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events:
body["origin_server_ts"] = e.origin_server_ts;
body["unsigned"] = e.unsigned_data;
nhlog::crypto()->info("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<StateKeeper> 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<StateKeeper> 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");

View file

@ -1,5 +1,5 @@
#include "Config.h"
#include "InfoMessage.h"
#include "Config.h"
#include <QDateTime>
#include <QPainter>