diff --git a/src/command_download.cc b/src/command_download.cc index 76544c0d..1734ae88 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -55,6 +55,7 @@ #include #include #include +#include #include #include "core/download.h" @@ -318,10 +319,11 @@ struct call_add_d_peer_t { call_add_d_peer_t(core::Download* d, int port) : m_download(d), m_port(port) { } void operator() (const sockaddr* sa, int err) { - if (sa == NULL) - control->core()->push_log("Could not resolve host."); - else + if (sa == NULL) { + lt_log_print(torrent::LOG_CONNECTION_WARN, "Could not resolve hostname for added peer."); + } else { m_download->download()->add_peer(sa, m_port); + } } core::Download* m_download; diff --git a/src/command_events.cc b/src/command_events.cc index 2c5928fe..8deda496 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -44,6 +44,7 @@ #include #include #include +#include #include "core/download.h" #include "core/download_list.h" @@ -235,7 +236,7 @@ apply_close_low_diskspace(int64_t arg) { } if (closed) - control->core()->push_log("Closed torrents due to low diskspace."); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Closed torrents due to low diskspace."); return torrent::Object(); } diff --git a/src/core/dht_manager.cc b/src/core/dht_manager.cc index f6319762..8000d200 100644 --- a/src/core/dht_manager.cc +++ b/src/core/dht_manager.cc @@ -42,6 +42,7 @@ #include #include #include +#include #include "rpc/parse_commands.h" @@ -76,7 +77,7 @@ DhtManager::load_dht_cache() { // If the cache file is corrupted we will just discard it with an // error message. if (cache_file.fail()) { - control->core()->push_log("DHT warning: Cache file corrupted, discarding."); + lt_log_print(torrent::LOG_DHT_WARN, "DHT cache file corrupted, discarding."); cache = torrent::Object::create_map(); } } @@ -88,7 +89,7 @@ DhtManager::load_dht_cache() { start_dht(); } catch (torrent::local_error& e) { - control->core()->push_log((std::string("DHT error: ") + e.what()).c_str()); + lt_log_print(torrent::LOG_DHT_WARN, "DHT failed: %s", e.what()); } } @@ -107,9 +108,7 @@ DhtManager::start_dht() { if (port <= 0) return; - char msg[128]; - snprintf(msg, sizeof(msg), "Starting DHT server on port %d.", port); - control->core()->push_log(msg); + lt_log_print(torrent::LOG_DHT_INFO, "Starting DHT server on port %d.", port); try { torrent::dht_manager()->start(port); @@ -126,7 +125,7 @@ DhtManager::start_dht() { m_dhtPrevBytesDown = 0; } catch (torrent::local_error& e) { - control->core()->push_log((std::string("DHT error: ") + e.what()).c_str()); + lt_log_print(torrent::LOG_DHT_ERROR, "DHT start failed: %s", e.what()); m_start = dht_off; } } @@ -138,7 +137,7 @@ DhtManager::stop_dht() { if (torrent::dht_manager()->is_active()) { log_statistics(true); - control->core()->push_log("Stopping DHT server."); + lt_log_print(torrent::LOG_DHT_INFO, "Stopping DHT server."); torrent::dht_manager()->stop(); } } @@ -220,7 +219,7 @@ DhtManager::log_statistics(bool force) { // We should have had clients ping us at least but have received // nothing, that means the UDP port is probably unreachable. if (torrent::dht_manager()->can_receive_queries()) - control->core()->push_log("Warning: DHT port appears to be unreachable, no queries received."); + lt_log_print(torrent::LOG_DHT_WARN, "DHT port appears to be unreachable, no queries received."); torrent::dht_manager()->set_can_receive(false); } @@ -228,7 +227,7 @@ DhtManager::log_statistics(bool force) { if (stats.queries_sent - m_dhtPrevQueriesSent > stats.num_nodes * 2 + 20 && stats.replies_received == m_dhtPrevRepliesReceived) { // No replies to over 20 queries plus two per node we have. Probably firewalled. if (!m_warned) - control->core()->push_log("Warning: DHT port appears to be firewalled, no replies received."); + lt_log_print(torrent::LOG_DHT_WARN, "DHT port appears to be firewalled, no replies received."); m_warned = true; return false; diff --git a/src/core/download_list.cc b/src/core/download_list.cc index e7bbbb32..cb47b8d3 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -50,6 +50,7 @@ #include #include #include +#include #include "rpc/parse_commands.h" @@ -90,7 +91,7 @@ DownloadList::session_save() { unsigned int c = std::count_if(begin(), end(), std::bind1st(std::mem_fun(&DownloadStore::save_resume), control->core()->download_store())); if (c != size()) - control->core()->push_log("Failed to save session torrents."); + lt_log_print(torrent::LOG_ERROR, "Failed to save session torrents."); control->dht_manager()->save_dht_cache(); } @@ -128,7 +129,7 @@ DownloadList::create(torrent::Object* obj, bool printLog) { delete obj; if (printLog) - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download: %s", e.what()); return NULL; } @@ -152,7 +153,7 @@ DownloadList::create(std::istream* str, bool printLog) { delete object; if (printLog) - control->core()->push_log("Could not create download, the input is not a valid torrent."); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download, the input is not a valid torrent."); return NULL; } @@ -163,7 +164,7 @@ DownloadList::create(std::istream* str, bool printLog) { delete object; if (printLog) - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download: %s", e.what()); return NULL; } @@ -232,7 +233,7 @@ DownloadList::open(Download* download) { return true; } catch (torrent::local_error& e) { - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not open download: %s", e.what()); return false; } } @@ -260,7 +261,7 @@ DownloadList::close(Download* download) { close_throw(download); } catch (torrent::local_error& e) { - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not close download: %s", e.what()); } } @@ -408,7 +409,7 @@ DownloadList::resume(Download* download, int flags) { DL_TRIGGER_EVENT(download, "event.download.resumed"); } catch (torrent::local_error& e) { - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not resume download: %s", e.what()); } } @@ -455,7 +456,7 @@ DownloadList::pause(Download* download, int flags) { //control->core()->download_store()->save(download); } catch (torrent::local_error& e) { - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not pause download: %s", e.what()); } } @@ -471,7 +472,7 @@ DownloadList::check_hash(Download* download) { hash_queue(download, Download::variable_hashing_rehash); } catch (torrent::local_error& e) { - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not check hash: %s", e.what()); } } @@ -532,7 +533,7 @@ DownloadList::hash_done(Download* download) { confirm_finished(download); } else { download->set_message("Hash check on download completion found bad chunks, consider using \"safe_sync\"."); - control->core()->push_log("Hash check on download completion found bad chunks, consider using \"safe_sync\"."); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Hash check on download completion found bad chunks, consider using \"safe_sync\"."); DL_TRIGGER_EVENT(download, "event.download.hash_final_failed"); } @@ -670,7 +671,7 @@ DownloadList::process_meta_download(Download* download) { std::string metafile = (*download->file_list()->begin())->frozen_path(); std::fstream file(metafile.c_str(), std::ios::in | std::ios::binary); if (!file.is_open()) { - control->core()->push_log("Could not read download metadata."); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not read download metadata."); return; } @@ -678,7 +679,7 @@ DownloadList::process_meta_download(Download* download) { file >> bencode->insert_key("info", torrent::Object()); if (file.fail()) { delete bencode; - control->core()->push_log("Could not create download, the input is not a valid torrent."); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download, the input is not a valid torrent."); return; } file.close(); diff --git a/src/core/manager.cc b/src/core/manager.cc index b8c1378a..13eb8a73 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -57,6 +57,7 @@ #include #include #include +#include #include "rpc/parse_commands.h" #include "utils/directory.h" @@ -579,7 +580,7 @@ Manager::receive_hashing_changed() { } else { (*itr)->set_hash_failed(true); - push_log(e.what()); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Hashing failed: %s", e.what()); } } } diff --git a/src/rpc/scgi_task.cc b/src/rpc/scgi_task.cc index 8ea5fcba..daf0973a 100644 --- a/src/rpc/scgi_task.cc +++ b/src/rpc/scgi_task.cc @@ -43,6 +43,7 @@ #include #include #include +#include #include "utils/socket_fd.h" @@ -182,6 +183,8 @@ SCgiTask::event_read() { write(m_parent->log_fd(), "\n---\n", sizeof("\n---\n")); } + lt_log_print(torrent::LOG_RPC_DEBUG, "---\n%*s\n---", m_bufferSize - std::distance(m_buffer, m_body), m_body); + // Close if the call failed, else stay open to write back data. if (!m_parent->receive_call(this, m_body, m_bufferSize - std::distance(m_buffer, m_body))) close(); @@ -240,6 +243,8 @@ SCgiTask::receive_write(const char* buffer, uint32_t length) { write(m_parent->log_fd(), "\n---\n", sizeof("\n---\n")); } + lt_log_print(torrent::LOG_RPC_DEBUG, "---\n%*s\n---", m_bufferSize, m_buffer); + event_write(); return true; } diff --git a/src/thread_base.cc b/src/thread_base.cc index 5cfcf7d6..715b8d10 100644 --- a/src/thread_base.cc +++ b/src/thread_base.cc @@ -46,6 +46,7 @@ #include #include #include +#include #include "globals.h" #include "control.h" @@ -170,9 +171,8 @@ ThreadBase::event_loop(ThreadBase* threadBase) { } catch (torrent::shutdown_exception& e) { acquire_global_lock(); - control->core()->push_log("Shutting down thread."); + lt_log_print(torrent::LOG_THREAD_NOTICE, "Shutting down thread."); release_global_lock(); - // sleep(20); } threadBase->m_state = STATE_INACTIVE; diff --git a/src/thread_base.h b/src/thread_base.h index 1c250b81..f6bda7b3 100644 --- a/src/thread_base.h +++ b/src/thread_base.h @@ -97,6 +97,8 @@ protected: void call_queued_items(); + // TODO: Add thread name. + pthread_t m_thread; state_type m_state; diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 518eda6c..f9e6ce4b 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -42,6 +42,7 @@ #include #include #include +#include #include "core/download.h" #include "core/download_list.h" @@ -328,7 +329,7 @@ DownloadList::receive_exit_input(Input type) { } } catch (torrent::input_error& e) { - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_WARN, "Input failed: %s", e.what()); } activate_display(DISPLAY_DOWNLOAD_LIST); diff --git a/src/ui/element_download_list.cc b/src/ui/element_download_list.cc index e8b26f07..41b37bee 100644 --- a/src/ui/element_download_list.cc +++ b/src/ui/element_download_list.cc @@ -39,6 +39,7 @@ #include #include #include +#include #include "core/download.h" #include "core/manager.h" @@ -152,7 +153,7 @@ ElementDownloadList::receive_command(const char* cmd) { m_view->set_last_changed(); } catch (torrent::input_error& e) { - control->core()->push_log(e.what()); + lt_log_print(torrent::LOG_WARN, "Command failed: %s", e.what()); return; } } @@ -194,7 +195,7 @@ ElementDownloadList::receive_cycle_throttle() { core::Download* download = *m_view->focus(); if (download->is_active()) { - control->core()->push_log("Cannot change throttle on active download."); + lt_log_print(torrent::LOG_TORRENT_WARN, "Cannot change throttle on active download."); return; }