* Added 'log.open_file' and 'log.add_output' options for using the new logging facilities.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1283 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2011-09-21 02:38:05 +00:00
parent 6faea70de2
commit 156d69c854
3 changed files with 58 additions and 21 deletions
+24
View File
@@ -48,7 +48,9 @@
#include <torrent/chunk_manager.h>
#include <torrent/data/file_manager.h>
#include <torrent/data/chunk_utils.h>
#include <torrent/utils/log.h>
#include <torrent/utils/log_files.h>
#include <torrent/utils/option_strings.h>
#include "core/download.h"
#include "core/download_list.h"
@@ -297,6 +299,25 @@ cmd_file_append(const torrent::Object::list_type& args) {
return torrent::Object();
}
torrent::Object
apply_log_open_file(const torrent::Object::list_type& args) {
if (args.size() != 2)
throw torrent::input_error("Invalid number of arguments.");
torrent::log_open_file_output(args.front().as_string().c_str(), args.back().as_string().c_str());
return torrent::Object();
}
torrent::Object
apply_log_add_output(const torrent::Object::list_type& args) {
if (args.size() != 2)
throw torrent::input_error("Invalid number of arguments.");
torrent::log_add_group_output(torrent::option_find_string(torrent::OPTION_LOG_GROUP, args.front().as_string().c_str()),
args.back().as_string().c_str());
return torrent::Object();
}
void
initialize_command_local() {
torrent::ChunkManager* chunkManager = torrent::chunk_manager();
@@ -390,6 +411,9 @@ initialize_command_local() {
CMD2_EXECUTE ("execute.capture", rpc::ExecFile::flag_throw | rpc::ExecFile::flag_expand_tilde | rpc::ExecFile::flag_capture);
CMD2_EXECUTE ("execute.capture_nothrow", rpc::ExecFile::flag_expand_tilde | rpc::ExecFile::flag_capture);
CMD2_ANY_LIST ("log.open_file", std::bind(&apply_log_open_file, std::placeholders::_2));
CMD2_ANY_LIST ("log.add_output", std::bind(&apply_log_add_output, std::placeholders::_2));
CMD2_ANY_STRING ("log.execute", std::bind(&apply_log, std::placeholders::_2, 0));
CMD2_ANY_STRING ("log.vmmap.dump", std::bind(&log_vmmap_dump, std::placeholders::_2));
CMD2_ANY_STRING_V("log.xmlrpc", std::bind(&ThreadWorker::set_xmlrpc_log, worker_thread, std::placeholders::_2));
+13 -15
View File
@@ -50,6 +50,7 @@
#include <torrent/data/file_manager.h>
#include <torrent/download/resource_manager.h>
#include <torrent/peer/peer_list.h>
#include <torrent/utils/log.h>
#include <torrent/utils/option_strings.h>
#include "core/dht_manager.h"
@@ -102,10 +103,11 @@ struct call_add_node_t {
call_add_node_t(int port) : 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_DHT_WARN, "Could not resolve host.");
} else {
torrent::dht_manager()->add_node(sa, m_port);
}
}
int m_port;
@@ -191,10 +193,7 @@ initialize_xmlrpc() {
rpc::xmlrpc.insert_command(itr->first, itr->second.m_parm, itr->second.m_doc);
}
char buffer[128];
sprintf(buffer, "XMLRPC initialized with %u functions.", count);
control->core()->push_log(buffer);
lt_log_print(torrent::LOG_RPC_INFO, "XMLRPC initialized with %u functions.", count);
}
torrent::Object
@@ -222,7 +221,7 @@ apply_scgi(const std::string& arg, int type) {
sa.sa_inet()->clear();
saPtr = &sa;
control->core()->push_log("The SCGI socket has not been bound to any address and likely poses a security risk.");
lt_log_print(torrent::LOG_RPC_WARN, "The SCGI socket has not been bound to any address and likely poses a security risk.");
} else if (std::sscanf(arg.c_str(), "%1023[^:]:%i%c", address, &port, &dummy) == 2) {
if ((err = rak::address_info::get_address_info(address, PF_INET, SOCK_STREAM, &ai)) != 0)
@@ -230,7 +229,7 @@ apply_scgi(const std::string& arg, int type) {
saPtr = ai->address();
control->core()->push_log("The SCGI socket is bound to a specific network device yet may still pose a security risk, consider using 'scgi_local'.");
lt_log_print(torrent::LOG_RPC_WARN, "The SCGI socket is bound to a specific network device yet may still pose a security risk, consider using 'scgi_local'.");
} else {
throw torrent::input_error("Could not parse address.");
@@ -464,12 +463,11 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) {
throw torrent::input_error(buffer);
}
snprintf(buffer, 2048, "Loaded %u %s address blocks (%u kb in-memory) from '%s'.",
lineNumber,
args.back().as_string().c_str(),
torrent::PeerList::ipv4_filter()->sizeof_data() / 1024,
args.front().as_string().c_str());
control->core()->push_log(buffer);
lt_log_print(torrent::LOG_CONNECTION_INFO, "Loaded %u %s address blocks (%u kb in-memory) from '%s'.",
lineNumber,
args.back().as_string().c_str(),
torrent::PeerList::ipv4_filter()->sizeof_data() / 1024,
args.front().as_string().c_str());
return torrent::Object();
}
+21 -6
View File
@@ -44,6 +44,7 @@
#include <torrent/torrent.h>
#include <torrent/exceptions.h>
#include <torrent/data/chunk_utils.h>
#include <torrent/utils/log.h>
#include <rak/functional.h>
#include <rak/error_number.h>
@@ -75,6 +76,8 @@
#include "thread_main.h"
#include "thread_worker.h"
namespace std { using namespace tr1; }
void handle_sigbus(int signum, siginfo_t* sa, void* ptr);
void do_panic(int signum);
void print_help();
@@ -195,19 +198,26 @@ 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);
control->core()->push_log("Disabled deprecated commands.");
lt_log_print(torrent::LOG_WARN, "Disabled deprecated commands.");
}
if (OptionParser::has_flag('I', argc, argv)) {
rpc::call_command_set_value("method.use_intermediate.set", 0);
control->core()->push_log("Disabled intermediate commands.");
lt_log_print(torrent::LOG_WARN, "Disabled intermediate commands.");
}
if (OptionParser::has_flag('K', argc, argv)) {
rpc::call_command_set_value("method.use_intermediate.set", 2);
control->core()->push_log("Allowing intermediate commands without xmlrpc.");
lt_log_print(torrent::LOG_WARN, "Allowing intermediate commands without xmlrpc.");
}
rpc::parse_command_multiple
@@ -832,10 +842,11 @@ main(int argc, char** argv) {
int firstArg = parse_options(control, argc, argv);
if (OptionParser::has_flag('n', argc, argv))
control->core()->push_log("Ignoring ~/.rtorrent.rc.");
else
if (OptionParser::has_flag('n', argc, argv)) {
lt_log_print(torrent::LOG_WARN, "Ignoring ~/.rtorrent.rc.");
} else {
rpc::parse_command_single(rpc::make_target(), "try_import = ~/.rtorrent.rc");
}
control->initialize();
@@ -878,6 +889,8 @@ main(int argc, char** argv) {
return -1;
}
torrent::log_cleanup();
delete control;
delete worker_thread;
delete main_thread;
@@ -946,6 +959,7 @@ handle_sigbus(int signum, siginfo_t* sa, void* ptr) {
printf("Chunk index: %u.\n", result.chunk_index);
printf("Chunk offset: %u.\n", result.chunk_offset);
torrent::log_cleanup();
std::abort();
}
@@ -990,6 +1004,7 @@ do_panic(int signum) {
if (signum == SIGBUS)
std::cout << "A bus error probably means you ran out of diskspace." << std::endl;
torrent::log_cleanup();
std::abort();
}