From 7ee4b147d9b0c75d861f4569866204f682c98490 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sat, 10 Oct 2026 18:48:47 +0900 Subject: [PATCH] Collapse cascading log levels into LOG_ERRORS / LOG_EVENTS / LOG_DEBUG_TRACE. --- doc/manual/logging.tex | 22 ++++++++------------ doc/rtorrent.rc-example | 3 ++- doc/rtorrent.rc.lua-example | 3 ++- src/command_dynamic.cc | 2 +- src/command_local.cc | 2 +- src/command_network.cc | 2 +- src/command_tracker.cc | 2 +- src/core/download_factory.cc | 4 ++-- src/core/download_list.cc | 2 +- src/main.cc | 37 +++++++++++++++++---------------- src/scgi/thread_scgi.cc | 6 +++--- src/session/session_manager.cc | 2 +- src/setup.cc | 2 +- src/ui/download_list.cc | 2 +- src/ui/element_download_list.cc | 2 +- src/ui/root.cc | 14 ++++++------- test/src/test_setup.cc | 6 +++--- 17 files changed, 56 insertions(+), 57 deletions(-) diff --git a/doc/manual/logging.tex b/doc/manual/logging.tex index df362f5b..fff37bdb 100644 --- a/doc/manual/logging.tex +++ b/doc/manual/logging.tex @@ -18,7 +18,8 @@ Some control over formatting will be provided at a later date. \begin{verbatim} # log.add_output = "logging event", "log name" -log.add_output = "info", "rtorrent.log" +log.add_output = "errors", "rtorrent.log" +log.add_output = "events", "rtorrent.log" log.add_output = "dht_all", "tracker.log" log.add_output = "tracker_events", "tracker.log" @@ -31,21 +32,16 @@ Each log handle can be added to multiple different logging events. \subsection{Logging events} \begin{verbatim} -"critical" -"error" -"warn" -"notice" -"info" -"debug" +"errors" +"events" +"debug_trace" \end{verbatim} -The above events receive logging events from all the sub-groups -displayed below, and each event also reciving events from the event -above in importance. +The above events are not cascading, so add both ``errors'' and +``events'' to an output to receive both. -Thus some high-volume sub-group events such as ``tracker\_debug'' are -not part of ``debug'' and every ``warn'' event will receive events -from ``error'', ``critical''. +High-volume sub-group events such as ``tracker\_debug'' are not part +of ``debug\_trace''. \begin{verbatim} "connection_*" diff --git a/doc/rtorrent.rc-example b/doc/rtorrent.rc-example index ed9aeea1..3778cf8e 100644 --- a/doc/rtorrent.rc-example +++ b/doc/rtorrent.rc-example @@ -104,7 +104,8 @@ print = (cat, "Logging to ", (cfg.logfile)) log.open_file = "log", (cfg.logfile) -log.add_output = "info", "log" +log.add_output = "errors", "log" +log.add_output = "events", "log" #log.add_output = "tracker_events", "log" #log.add_output = "tracker_requests", "log" diff --git a/doc/rtorrent.rc.lua-example b/doc/rtorrent.rc.lua-example index 08d37fec..2339aba1 100644 --- a/doc/rtorrent.rc.lua-example +++ b/doc/rtorrent.rc.lua-example @@ -135,7 +135,8 @@ rc.schedule2('watch_load', '11', '10', 'load.verbose=(cat, (cfg.watch), "load/*. -- Groups = connection_* dht_* peer_* rpc_* storage_* thread_* tracker_* torrent_* rc.print('Logging to '..rc.cfg.logfile()) rc.log.open_file('log', rc.cfg.logfile()) -rc.log.add_output('info', 'log') +rc.log.add_output('errors', 'log') +rc.log.add_output('events', 'log') --rc.log.add_output('tracker_events', 'log') --rc.log.add_output('tracker_requests', 'log') diff --git a/src/command_dynamic.cc b/src/command_dynamic.cc index edbc3278..726d0267 100644 --- a/src/command_dynamic.cc +++ b/src/command_dynamic.cc @@ -394,7 +394,7 @@ cmd_catch(rpc::target_type target, const torrent::Object& args) { try { return rpc::call_object(args, target); } catch (torrent::input_error& e) { - lt_log_print(torrent::LOG_WARN, "Caught exception: '%s'.", e.what()); + lt_log_print(torrent::LOG_ERRORS, "Caught exception: '%s'.", e.what()); return torrent::Object(); } } diff --git a/src/command_local.cc b/src/command_local.cc index 7bc71b61..505a138b 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -88,7 +88,7 @@ initialize_command_local() { CMD_ANY_VALUE_V ("pieces.sync.timeout.set", [](auto, auto& value) { return torrent::runtime::memory_manager()->set_timeout_sync(value); }); CMD_ANY ("pieces.sync.timeout_safe", [](auto, auto) { return 0; }); CMD_ANY_VALUE_V ("pieces.sync.timeout_safe.set", [](auto, auto) { - lt_log_print(torrent::LOG_WARN, "pieces.sync.timeout_safe.set is no longer supported and does nothing."); + lt_log_print(torrent::LOG_ERRORS, "pieces.sync.timeout_safe.set is no longer supported and does nothing."); }); CMD_ANY ("pieces.sync.queue_size", [](auto, auto) { return torrent::runtime::memory_manager()->sync_queue_block_count(); }); diff --git a/src/command_network.cc b/src/command_network.cc index 275a4e91..bb1d19d7 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -106,7 +106,7 @@ apply_obsolete_encryption(const torrent::Object::list_type& args) { } } - lt_log_print(torrent::LOG_WARN, "Obsolete encryption options used, use 'handshake_{deny,allow,prefer,require}, stream_{deny,allow,prefer,require}' instead."); + lt_log_print(torrent::LOG_ERRORS, "Obsolete encryption options used, use 'handshake_{deny,allow,prefer,require}, stream_{deny,allow,prefer,require}' instead."); torrent::runtime::network_config()->set_encryption_modes(handshake_mode, stream_mode); return {}; diff --git a/src/command_tracker.cc b/src/command_tracker.cc index 3a53cc47..171d1e86 100644 --- a/src/command_tracker.cc +++ b/src/command_tracker.cc @@ -133,7 +133,7 @@ initialize_command_tracker() { CMD2_ANY ("trackers.use_udp", [](auto, auto) { return true; }); CMD2_ANY_VALUE_V ("trackers.use_udp.set", [](auto, auto) { - lt_log_print(torrent::LOG_ERROR, "trackers.use_udp.set is no longer supported", 0); + lt_log_print(torrent::LOG_ERRORS, "trackers.use_udp.set is no longer supported", 0); }) CMD2_ANY_STRING_V ("dht.mode.set", [](auto, auto& str) { return control->dht_manager()->set_mode_by_user(str); }); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 74c548dc..bb5c512f 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -184,7 +184,7 @@ DownloadFactory::receive_success() { libtorrent_resume_object = download_factory_load_stream((expand_path(m_uri) + ".libtorrent_resume").c_str(), &session_invalid); if (session_invalid) - lt_log_print(torrent::LOG_ERROR, "%s: %s", session_invalid_message, m_uri.c_str()); + lt_log_print(torrent::LOG_ERRORS, "%s: %s", session_invalid_message, m_uri.c_str()); } uint32_t tracker_key; @@ -313,7 +313,7 @@ DownloadFactory::receive_success() { } catch (const torrent::input_error& e) { std::string msg = std::string(session_invalid_message) + ": " + e.what(); - lt_log_print(torrent::LOG_ERROR, "%s: %s", msg.c_str(), m_uri.c_str()); + lt_log_print(torrent::LOG_ERRORS, "%s: %s", msg.c_str(), m_uri.c_str()); if (m_printLog) m_manager->push_log_std(msg + ": \"" + m_uri + "\""); diff --git a/src/core/download_list.cc b/src/core/download_list.cc index 8079f7b4..12eb440b 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -61,7 +61,7 @@ DownloadList::clear() { torrent::download_remove(*download->download()); } catch (torrent::internal_error& e) { - lt_log_print(torrent::LOG_ERROR, "DownloadList::clear() failed to close or remove download: %s", e.what()); + lt_log_print(torrent::LOG_ERRORS, "DownloadList::clear() failed to close or remove download: %s", e.what()); error_count++; continue; } diff --git a/src/main.cc b/src/main.cc index 980a2450..ad6d9f78 100644 --- a/src/main.cc +++ b/src/main.cc @@ -152,10 +152,11 @@ main(int argc, char** argv) { SignalHandler::set_sigaction_handler(SIGBUS, &handle_sigbus); - torrent::log_add_group_output(torrent::LOG_NOTICE, "important"); + torrent::log_add_group_output(torrent::LOG_ERRORS, "important"); torrent::log_add_group_output(torrent::LOG_DHT_ERROR, "important"); - torrent::log_add_group_output(torrent::LOG_INFO, "complete"); + torrent::log_add_group_output(torrent::LOG_ERRORS, "complete"); + torrent::log_add_group_output(torrent::LOG_EVENTS, "complete"); torrent::log_add_group_output(torrent::LOG_DHT_ERROR, "complete"); torrent::log_add_group_output(torrent::LOG_DHT_CONTROLLER, "complete"); @@ -175,17 +176,17 @@ main(int argc, char** argv) { if (OptionParser::has_flag('D', argc, argv)) { rpc::call_command_set_value("method.use_deprecated.set", true); - lt_log_print(torrent::LOG_WARN, "Enabled deprecated commands."); + lt_log_print(torrent::LOG_ERRORS, "Enabled deprecated commands."); } if (OptionParser::has_flag('I', argc, argv)) { rpc::call_command_set_value("method.use_intermediate.set", 0); - lt_log_print(torrent::LOG_WARN, "Disabled intermediate commands."); + lt_log_print(torrent::LOG_ERRORS, "Disabled intermediate commands."); } if (OptionParser::has_flag('K', argc, argv)) { rpc::call_command_set_value("method.use_intermediate.set", 2); - lt_log_print(torrent::LOG_WARN, "Allowing intermediate commands without xmlrpc."); + lt_log_print(torrent::LOG_ERRORS, "Allowing intermediate commands without xmlrpc."); } rpc::parse_command_multiple @@ -372,11 +373,11 @@ main(int argc, char** argv) { rpc::rpc.mark_safe("network.http.proxy_address"); CMD2_ANY_VALUE_V("network.http.max_total_connections.set", [](auto, auto) { - lt_log_print(torrent::LOG_WARN, "network.http.max_total_connections.set is deprecated, use system.sockets.http.min_alloc.set instead."); + lt_log_print(torrent::LOG_ERRORS, "network.http.max_total_connections.set is deprecated, use system.sockets.http.min_alloc.set instead."); }); CMD2_ANY_VALUE_V("network.max_open_files.set", [](auto, auto) { - lt_log_print(torrent::LOG_WARN, "network.max_open_files.set is deprecated, use system.sockets.files.min_alloc.set instead."); + lt_log_print(torrent::LOG_ERRORS, "network.max_open_files.set is deprecated, use system.sockets.files.min_alloc.set instead."); }); // TODO: Keep d.directory_base for a while as it is widely used. @@ -419,16 +420,16 @@ main(int argc, char** argv) { CMD_REDIRECT("max_memory_usage", "pieces.memory.max.set"); CMD_ANY_LIST("throttle.ip", []( auto, auto) { - lt_log_print(torrent::LOG_WARN, "The 'throttle.ip' command is deprecated and does nothing."); + lt_log_print(torrent::LOG_ERRORS, "The 'throttle.ip' command is deprecated and does nothing."); return torrent::Object(); }); CMD_ANY("network.port_open", [](auto, auto) { - lt_log_print(torrent::LOG_WARN, "The 'network.port_open' command is deprecated and does nothing."); + lt_log_print(torrent::LOG_ERRORS, "The 'network.port_open' command is deprecated and does nothing."); return torrent::Object(); }); CMD_ANY("network.port_open.set", [](auto, auto) { - lt_log_print(torrent::LOG_WARN, "The 'network.port_open.set' command is deprecated and does nothing."); + lt_log_print(torrent::LOG_ERRORS, "The 'network.port_open.set' command is deprecated and does nothing."); return torrent::Object(); }); @@ -443,7 +444,7 @@ main(int argc, char** argv) { if (fd == -1) { if (errno == EAFNOSUPPORT) { - lt_log_print(torrent::LOG_WARN, "disabling ipv6 support, not available on system"); + lt_log_print(torrent::LOG_ERRORS, "disabling ipv6 support, not available on system"); rpc::call_command_set_value("network.block.ipv6.set", true); } } else { @@ -455,7 +456,7 @@ main(int argc, char** argv) { parse_config_file(argc, argv, [](auto& path) { if (path.empty()) { - lt_log_print(torrent::LOG_WARN, "Ignoring rtorrent.rc."); + lt_log_print(torrent::LOG_ERRORS, "Ignoring rtorrent.rc."); return; } @@ -499,7 +500,7 @@ main(int argc, char** argv) { << e.what() << std::endl << e.backtrace(); - lt_log_print_dump(torrent::LOG_CRITICAL, e.backtrace().c_str(), e.backtrace().size(), + lt_log_print_dump(torrent::LOG_ERRORS, e.backtrace().c_str(), e.backtrace().size(), "Caught internal_error: '%s'.", e.what()); torrent::log_cleanup(); @@ -511,7 +512,7 @@ main(int argc, char** argv) { std::cout << "rtorrent: caught" << typeid(e).name() << " : " << e.what() << std::endl; - lt_log_print(torrent::LOG_CRITICAL, "Caught exception: '%s'.", e.what()); + lt_log_print(torrent::LOG_ERRORS, "Caught exception: '%s'.", e.what()); torrent::log_cleanup(); return -1; @@ -588,9 +589,9 @@ handle_sigbus(int signum, siginfo_t* sa, [[maybe_unused]] void* ptr) { handle_sigbus_exit: std::cout << output.rdbuf(); - if (lt_log_is_valid(torrent::LOG_CRITICAL)) { + if (lt_log_is_valid(torrent::LOG_ERRORS)) { std::string dump = output.str(); - lt_log_print_dump(torrent::LOG_CRITICAL, dump.c_str(), dump.size(), "Caught signal: '%s'.", signal_reason); + lt_log_print_dump(torrent::LOG_ERRORS, dump.c_str(), dump.size(), "Caught signal: '%s'.", signal_reason); } torrent::log_cleanup(); @@ -629,9 +630,9 @@ do_panic(int signum) { std::cout << output.rdbuf(); - if (lt_log_is_valid(torrent::LOG_CRITICAL)) { + if (lt_log_is_valid(torrent::LOG_ERRORS)) { std::string dump = output.str(); - lt_log_print_dump(torrent::LOG_CRITICAL, dump.c_str(), dump.size(), "Caught signal: '%s.", strsignal(signum)); + lt_log_print_dump(torrent::LOG_ERRORS, dump.c_str(), dump.size(), "Caught signal: '%s.", strsignal(signum)); } torrent::log_cleanup(); diff --git a/src/scgi/thread_scgi.cc b/src/scgi/thread_scgi.cc index 3ff0d5f6..ed26f5f7 100644 --- a/src/scgi/thread_scgi.cc +++ b/src/scgi/thread_scgi.cc @@ -82,7 +82,7 @@ ThreadScgi::change_rpc_log() { ::close(scgi()->log_fd()); scgi()->set_log_fd(-1); - lt_log_print(torrent::LOG_NOTICE, "Closed RPC log.", 0); + lt_log_print(torrent::LOG_EVENTS, "Closed RPC log.", 0); } if (m_rpc_log_filename.empty()) @@ -91,11 +91,11 @@ ThreadScgi::change_rpc_log() { scgi()->set_log_fd(open(expand_path(m_rpc_log_filename).c_str(), O_WRONLY | O_APPEND | O_CREAT, 0644)); if (scgi()->log_fd() == -1) { - lt_log_print(torrent::LOG_NOTICE, "Could not open RPC log file '%s'.", m_rpc_log_filename.c_str()); + lt_log_print(torrent::LOG_EVENTS, "Could not open RPC log file '%s'.", m_rpc_log_filename.c_str()); return; } - lt_log_print(torrent::LOG_NOTICE, "Logging RPC events to '%s'.", m_rpc_log_filename.c_str()); + lt_log_print(torrent::LOG_EVENTS, "Logging RPC events to '%s'.", m_rpc_log_filename.c_str()); } void diff --git a/src/session/session_manager.cc b/src/session/session_manager.cc index d268dfc7..2536d133 100644 --- a/src/session/session_manager.cc +++ b/src/session/session_manager.cc @@ -417,7 +417,7 @@ SessionManager::process_finished_saves() { continue; } - lt_log_print(torrent::LOG_ERROR, "Storage errors saving session data for download: ignored:%u : %s", m_ignored_storage_error_count, e.what()); + lt_log_print(torrent::LOG_ERRORS, "Storage errors saving session data for download: ignored:%u : %s", m_ignored_storage_error_count, e.what()); m_last_storage_error_message = torrent::this_thread::cached_time(); m_ignored_storage_error_count = 0; diff --git a/src/setup.cc b/src/setup.cc index bd6766ba..4160483c 100644 --- a/src/setup.cc +++ b/src/setup.cc @@ -142,7 +142,7 @@ parse_config_file_comments(const std::string& path) { else throw torrent::input_error("Unknown command in config file comment: " + line); - lt_log_print(torrent::LOG_NOTICE, "Pre-config command: %s=%s", command.c_str(), args.c_str()); + lt_log_print(torrent::LOG_EVENTS, "Pre-config command: %s=%s", command.c_str(), args.c_str()); } } diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 18e8b4b7..12d5efb5 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -366,7 +366,7 @@ DownloadList::receive_exit_input(Input type) { } } catch (torrent::input_error& e) { - lt_log_print(torrent::LOG_WARN, "Input failed: %s", e.what()); + lt_log_print(torrent::LOG_ERRORS, "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 57f9a2ea..13618b66 100644 --- a/src/ui/element_download_list.cc +++ b/src/ui/element_download_list.cc @@ -119,7 +119,7 @@ ElementDownloadList::receive_command(const char* cmd) { m_view->set_last_changed(); } catch (torrent::input_error& e) { - lt_log_print(torrent::LOG_WARN, "Command failed: %s", e.what()); + lt_log_print(torrent::LOG_ERRORS, "Command failed: %s", e.what()); return; } } diff --git a/src/ui/root.cc b/src/ui/root.cc index e9ed4437..f1893883 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -380,7 +380,7 @@ Root::set_input_history_size(int size) { void Root::load_input_history() { if (m_control == nullptr || !session_thread::manager()->is_used()) { - lt_log_print(torrent::LOG_DEBUG, "ignoring input history file"); + lt_log_print(torrent::LOG_DEBUG_TRACE, "ignoring input history file"); return; } @@ -415,10 +415,10 @@ Root::load_input_history() { } if (history_file.bad()) { - lt_log_print(torrent::LOG_DEBUG, "input history file corrupted, discarding (path:%s)", history_filename.c_str()); + lt_log_print(torrent::LOG_DEBUG_TRACE, "input history file corrupted, discarding (path:%s)", history_filename.c_str()); return; } else { - lt_log_print(torrent::LOG_DEBUG, "input history file read (path:%s)", history_filename.c_str()); + lt_log_print(torrent::LOG_DEBUG_TRACE, "input history file read (path:%s)", history_filename.c_str()); } for (const auto& [entry, category] : input_history_tmp) { @@ -441,7 +441,7 @@ Root::load_input_history() { } } } else { - lt_log_print(torrent::LOG_DEBUG, "could not open input history file (path:%s)", history_filename.c_str()); + lt_log_print(torrent::LOG_DEBUG_TRACE, "could not open input history file (path:%s)", history_filename.c_str()); } } @@ -455,7 +455,7 @@ Root::save_input_history() { auto history_file = std::fstream(history_filename_tmp.c_str(), std::ios::out | std::ios::trunc); if (!history_file.is_open()) { - lt_log_print(torrent::LOG_DEBUG, "could not open input history file for writing (path:%s)", history_filename.c_str()); + lt_log_print(torrent::LOG_DEBUG_TRACE, "could not open input history file for writing (path:%s)", history_filename.c_str()); return; } @@ -471,10 +471,10 @@ Root::save_input_history() { history_file.close(); if (!history_file.good()) { - lt_log_print(torrent::LOG_DEBUG, "input history file corrupted during writing, discarding (path:%s)", history_filename.c_str()); + lt_log_print(torrent::LOG_DEBUG_TRACE, "input history file corrupted during writing, discarding (path:%s)", history_filename.c_str()); return; } else { - lt_log_print(torrent::LOG_DEBUG, "input history file written (path:%s)", history_filename.c_str()); + lt_log_print(torrent::LOG_DEBUG_TRACE, "input history file written (path:%s)", history_filename.c_str()); } std::rename(history_filename_tmp.c_str(), history_filename.c_str()); diff --git a/test/src/test_setup.cc b/test/src/test_setup.cc index 9dd8bcc5..6cacaf8d 100644 --- a/test/src/test_setup.cc +++ b/test/src/test_setup.cc @@ -57,7 +57,7 @@ assert_arg_count_error(const std::string& line) { void TestSetup::test_config_comment_log_add_output() { - temp_config_file file("# do:log.add_output=debug,test_output"); + temp_config_file file("# do:log.add_output=debug_trace,test_output"); CPPUNIT_ASSERT_NO_THROW(parse_config_file_comments(file.path())); } @@ -69,10 +69,10 @@ TestSetup::test_config_comment_log_add_output_no_args() { void TestSetup::test_config_comment_log_add_output_one_arg() { - assert_arg_count_error("# do:log.add_output=debug"); + assert_arg_count_error("# do:log.add_output=debug_trace"); } void TestSetup::test_config_comment_log_add_output_too_many_args() { - assert_arg_count_error("# do:log.add_output=debug,test_output,extra"); + assert_arg_count_error("# do:log.add_output=debug_trace,test_output,extra"); }