mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-14 13:16:17 +00:00
Use log_buffer for console logs.
This commit is contained in:
+7
-2
@@ -137,13 +137,18 @@ Manager::handshake_log(const sockaddr* sa, int msg, int err, const torrent::Hash
|
||||
|
||||
void
|
||||
Manager::push_log(const char* msg) {
|
||||
if (!pthread_equal(pthread_self(), torrent::main_thread()->pthread()))
|
||||
throw torrent::internal_error("Manager::push_log(...): Cannot call this function from other threads than 'main'.");
|
||||
|
||||
m_logImportant.push_front(msg);
|
||||
m_logComplete.push_front(msg);
|
||||
|
||||
m_log_important->lock_and_push_log(msg, strlen(msg), 0);
|
||||
}
|
||||
|
||||
Manager::Manager() :
|
||||
m_hashingView(NULL)
|
||||
// m_pollManager(NULL) {
|
||||
m_hashingView(NULL),
|
||||
m_log_important(torrent::log_open_log_buffer("important"))
|
||||
{
|
||||
m_downloadStore = new DownloadStore();
|
||||
m_downloadList = new DownloadList();
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
#include <torrent/utils/log_buffer.h>
|
||||
#include <torrent/connection_manager.h>
|
||||
|
||||
#include "download_list.h"
|
||||
@@ -88,6 +89,9 @@ public:
|
||||
Log& get_log_important() { return m_logImportant; }
|
||||
Log& get_log_complete() { return m_logComplete; }
|
||||
|
||||
torrent::log_buffer* log_important() { return m_log_important; }
|
||||
// torrent::log_buffer* log_complete() { return m_log_complete; }
|
||||
|
||||
ThrottleMap& throttles() { return m_throttles; }
|
||||
torrent::ThrottlePair get_throttle(const std::string& name);
|
||||
|
||||
@@ -154,6 +158,9 @@ private:
|
||||
|
||||
Log m_logImportant;
|
||||
Log m_logComplete;
|
||||
|
||||
torrent::log_buffer* m_log_important;
|
||||
// torrent::log_buffer* m_log_complete;
|
||||
};
|
||||
|
||||
// Meh, cleanup.
|
||||
|
||||
+15
-11
@@ -37,6 +37,8 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/utils/thread_base.h>
|
||||
|
||||
#include "canvas.h"
|
||||
#include "utils.h"
|
||||
@@ -44,37 +46,38 @@
|
||||
|
||||
namespace display {
|
||||
|
||||
WindowLog::WindowLog(core::Log* l) :
|
||||
WindowLog::WindowLog(torrent::log_buffer* l) :
|
||||
Window(new Canvas, 0, 0, 0, extent_full, extent_static),
|
||||
m_log(l) {
|
||||
|
||||
m_taskUpdate.slot() = std::tr1::bind(&WindowLog::receive_update, this);
|
||||
|
||||
// We're trying out scheduled tasks instead.
|
||||
m_connUpdate = l->signal_update().connect(sigc::mem_fun(*this, &WindowLog::receive_update));
|
||||
unsigned int signal_index = torrent::main_thread()->signal_bitfield()->add_signal(std::tr1::bind(&WindowLog::receive_update, this));
|
||||
|
||||
m_log->lock_and_set_update_slot(std::tr1::bind(&torrent::thread_base::send_event_signal, torrent::main_thread(), signal_index, false));
|
||||
}
|
||||
|
||||
WindowLog::~WindowLog() {
|
||||
priority_queue_erase(&taskScheduler, &m_taskUpdate);
|
||||
m_connUpdate.disconnect();
|
||||
}
|
||||
|
||||
WindowLog::iterator
|
||||
WindowLog::find_older() {
|
||||
return m_log->find_older(cachedTime - rak::timer::from_seconds(60));
|
||||
return m_log->find_older(cachedTime.seconds() - 60);
|
||||
// return m_log->begin();
|
||||
}
|
||||
|
||||
void
|
||||
WindowLog::redraw() {
|
||||
m_canvas->erase();
|
||||
|
||||
int pos = m_canvas->height();
|
||||
int pos = 0;
|
||||
|
||||
for (core::Log::iterator itr = m_log->begin(), last = find_older(); itr != last && pos > 0; ++itr, --pos) {
|
||||
for (iterator itr = find_older(), last = m_log->end(); itr != last && pos < m_canvas->height(); ++itr, ++pos) {
|
||||
char buffer[16];
|
||||
print_hhmmss_local(buffer, buffer + 16, static_cast<time_t>(itr->first.seconds()));
|
||||
print_hhmmss_local(buffer, buffer + 16, static_cast<time_t>(itr->timestamp));
|
||||
|
||||
m_canvas->print(0, pos - 1, "(%s) %s", buffer, itr->second.c_str());
|
||||
m_canvas->print(0, pos, "(%s) %s", buffer, itr->message.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,11 +89,12 @@ WindowLog::receive_update() {
|
||||
return;
|
||||
|
||||
iterator itr = find_older();
|
||||
extent_type height = std::min(std::distance(m_log->begin(), itr), (std::iterator_traits<iterator>::difference_type)10);
|
||||
extent_type height = std::min(std::distance(itr, (iterator)m_log->end()), (std::iterator_traits<iterator>::difference_type)10);
|
||||
|
||||
if (height != m_maxHeight) {
|
||||
m_minHeight = height != 0 ? 1 : 0;
|
||||
m_maxHeight = height;
|
||||
mark_dirty();
|
||||
m_slotAdjust();
|
||||
|
||||
} else {
|
||||
@@ -100,7 +104,7 @@ WindowLog::receive_update() {
|
||||
priority_queue_erase(&taskScheduler, &m_taskUpdate);
|
||||
|
||||
if (height != 0)
|
||||
priority_queue_insert(&taskScheduler, &m_taskUpdate, (cachedTime + rak::timer::from_seconds(30)).round_seconds());
|
||||
priority_queue_insert(&taskScheduler, &m_taskUpdate, (cachedTime + rak::timer::from_seconds(5)).round_seconds());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,9 +37,7 @@
|
||||
#ifndef RTORRENT_DISPLAY_WINDOW_LOG_H
|
||||
#define RTORRENT_DISPLAY_WINDOW_LOG_H
|
||||
|
||||
#include <sigc++/connection.h>
|
||||
|
||||
#include "core/log.h"
|
||||
#include <torrent/utils/log_buffer.h>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
@@ -47,9 +45,9 @@ namespace display {
|
||||
|
||||
class WindowLog : public Window {
|
||||
public:
|
||||
typedef core::Log::iterator iterator;
|
||||
typedef torrent::log_buffer::const_iterator iterator;
|
||||
|
||||
WindowLog(core::Log* l);
|
||||
WindowLog(torrent::log_buffer* l);
|
||||
~WindowLog();
|
||||
|
||||
virtual void redraw();
|
||||
@@ -59,10 +57,8 @@ public:
|
||||
private:
|
||||
inline iterator find_older();
|
||||
|
||||
core::Log* m_log;
|
||||
sigc::connection m_connUpdate;
|
||||
|
||||
rak::priority_item m_taskUpdate;
|
||||
torrent::log_buffer* m_log;
|
||||
rak::priority_item m_taskUpdate;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+5
-7
@@ -183,6 +183,9 @@ main(int argc, char** argv) {
|
||||
|
||||
cachedTime = rak::timer::current();
|
||||
|
||||
// Initialize logging:
|
||||
torrent::log_initialize();
|
||||
|
||||
control = new Control;
|
||||
|
||||
worker_thread = new ThreadWorker();
|
||||
@@ -205,6 +208,8 @@ main(int argc, char** argv) {
|
||||
// to process new non-socket events.
|
||||
SignalHandler::set_handler(SIGUSR1, sigc::ptr_fun(&do_nothing));
|
||||
|
||||
torrent::log_add_group_output(torrent::LOG_INFO, "important");
|
||||
|
||||
torrent::Poll::slot_create_poll() = std::tr1::bind(&core::create_poll);
|
||||
|
||||
torrent::initialize();
|
||||
@@ -215,13 +220,6 @@ main(int argc, char** argv) {
|
||||
// torrent::ConnectionManager* are valid etc.
|
||||
initialize_commands();
|
||||
|
||||
// Initialize logging:
|
||||
torrent::log_initialize();
|
||||
torrent::log_open_output("console", std::bind(&core::Manager::push_log, control->core(), std::placeholders::_1));
|
||||
torrent::log_add_group_output(torrent::LOG_INFO, "console");
|
||||
|
||||
lt_log_print(torrent::LOG_INFO, "Started logging to 'console'.");
|
||||
|
||||
if (OptionParser::has_flag('D', argc, argv)) {
|
||||
rpc::call_command_set_value("method.use_deprecated.set", false);
|
||||
lt_log_print(torrent::LOG_WARN, "Disabled deprecated commands.");
|
||||
|
||||
@@ -77,7 +77,7 @@ DownloadList::DownloadList() :
|
||||
m_uiArray[DISPLAY_LOG] = new ElementLogComplete(&control->core()->get_log_complete());
|
||||
m_uiArray[DISPLAY_STRING_LIST] = new ElementStringList();
|
||||
|
||||
m_windowLog = new WLog(&control->core()->get_log_important());
|
||||
m_windowLog = new WLog(control->core()->log_important());
|
||||
|
||||
setup_keys();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user