diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a95ad005..2274f5ab 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3402,3 +3402,7 @@ testGetDifference = Ok; testUseUpdate = Update; //@description Does nothing and ensures that the Error object is used; for testing only testUseError = Error; +//@description Changes verbosity level for a specified log tag; for testing only. This is an offline method. Can be called before authorization. Can be called synchronously +//@tag Logging tag to change verbosity level (one of "td_init", "update_file", "connections", "binlog", "proxy", "net_query", "td_requests", "dc", "files", "mtproto", "raw_mtproto", "fd", "actor", "buffer", "sqlite") +//@new_verbosity_level New verbosity level; 0-1023 +testSetLogTagVerbosityLevel tag:string new_verbosity_level:int32 = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 2003be21..1604efac 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0a34cce2..ed89bfc4 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -73,6 +73,8 @@ #include "td/mtproto/utils.h" // for create_storer, fetch_result, etc, TODO +#include "tdnet/td/net/TransparentProxy.h" + #include "td/utils/buffer.h" #include "td/utils/filesystem.h" #include "td/utils/format.h" @@ -3251,6 +3253,7 @@ bool Td::is_synchronous_request(int32 id) { case td_api::getFileExtension::ID: case td_api::cleanFileName::ID: case td_api::getLanguagePackString::ID: + case td_api::testSetLogTagVerbosityLevel::ID: return true; default: return false; @@ -6907,6 +6910,73 @@ void Td::on_request(uint64 id, td_api::testGetDifference &request) { send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); } +static int *get_log_verbosity_level(Slice name) { + if (name == "td_init") { + return &VERBOSITY_NAME(td_init); + } + if (name == "update_file") { + return &VERBOSITY_NAME(update_file); + } + if (name == "connections") { + return &VERBOSITY_NAME(connections); + } + if (name == "binlog") { + return &VERBOSITY_NAME(binlog); + } + if (name == "proxy") { + return &VERBOSITY_NAME(proxy); + } + if (name == "net_query") { + return &VERBOSITY_NAME(net_query); + } + if (name == "td_requests") { + return &VERBOSITY_NAME(td_requests); + } + if (name == "dc") { + return &VERBOSITY_NAME(dc); + } + if (name == "files") { + return &VERBOSITY_NAME(files); + } + if (name == "mtproto") { + return &VERBOSITY_NAME(mtproto); + } + if (name == "raw_mtproto") { + return &VERBOSITY_NAME(raw_mtproto); + } + if (name == "fd") { + return &VERBOSITY_NAME(fd); + } + if (name == "actor") { + return &VERBOSITY_NAME(actor); + } + if (name == "buffer") { + return &VERBOSITY_NAME(buffer); + } + if (name == "sqlite") { + return &VERBOSITY_NAME(sqlite); + } + return nullptr; +} + +void Td::on_request(uint64 id, td_api::testSetLogTagVerbosityLevel &request) { + UNREACHABLE(); +} + +td_api::object_ptr Td::do_static_request(const td_api::testSetLogTagVerbosityLevel &request) { + if (request.new_verbosity_level_ < 0 || request.new_verbosity_level_ > 1023) { + return td_api::make_object(400, "Wrong new verbosity level"); + } + + int *level = get_log_verbosity_level(request.tag_); + if (level == nullptr) { + return td_api::make_object(400, "Log tag is not found"); + } + *level = static_cast(request.new_verbosity_level_); + + return td_api::make_object(); +} + void Td::on_request(uint64 id, td_api::testUseUpdate &request) { send_closure(actor_id(this), &Td::send_result, id, nullptr); } diff --git a/td/telegram/Td.h b/td/telegram/Td.h index cad3a1b6..0d66fd7b 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -906,6 +906,7 @@ class Td final : public NetQueryCallback { // test void on_request(uint64 id, td_api::testNetwork &request); void on_request(uint64 id, td_api::testGetDifference &request); + void on_request(uint64 id, td_api::testSetLogTagVerbosityLevel &request); void on_request(uint64 id, td_api::testUseUpdate &request); void on_request(uint64 id, td_api::testUseError &request); void on_request(uint64 id, td_api::testCallEmpty &request); @@ -925,6 +926,7 @@ class Td final : public NetQueryCallback { static td_api::object_ptr do_static_request(const td_api::getFileExtension &request); static td_api::object_ptr do_static_request(const td_api::cleanFileName &request); static td_api::object_ptr do_static_request(const td_api::getLanguagePackString &request); + static td_api::object_ptr do_static_request(const td_api::testSetLogTagVerbosityLevel &request); Status init(DbKey key) TD_WARN_UNUSED_RESULT; void clear(); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 17a11b4a..74a1a221 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3381,6 +3381,16 @@ class CliClient final : public Actor { td::Log::set_verbosity_level(static_cast(op.size())); } else if (op[0] == 'v' && ('0' <= op[1] && op[1] <= '9')) { td::Log::set_verbosity_level(to_integer(op.substr(1))); + } else if (op == "sltvl" || op == "sltvle") { + string tag; + string level; + std::tie(tag, level) = split(args); + auto request = make_tl_object(tag, to_integer(level)); + if (op == "sltvl") { + send_request(std::move(request)); + } else { + execute(std::move(request)); + } } else if (op == "q" || op == "Quit") { quit(); } else if (op == "dnq" || op == "DumpNetQueries") { diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 03f5f7b6..2d88c29a 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -35,7 +35,7 @@ namespace td { -static int VERBOSITY_NAME(update_file) = VERBOSITY_NAME(DEBUG); +int VERBOSITY_NAME(update_file) = VERBOSITY_NAME(DEBUG); FileNode *FileNodePtr::operator->() const { return get(); diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index e36ac765..1bc4eb6d 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -35,6 +35,8 @@ namespace td { +extern int VERBOSITY_NAME(update_file); + enum class FileLocationSource : int8 { None, FromUser, FromDb, FromServer }; class FileNode { diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 493876e4..faf319df 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -41,7 +41,7 @@ namespace td { -static int VERBOSITY_NAME(connections) = VERBOSITY_NAME(DEBUG) + 8; +int VERBOSITY_NAME(connections) = VERBOSITY_NAME(DEBUG) + 8; namespace detail { diff --git a/td/telegram/net/ConnectionCreator.h b/td/telegram/net/ConnectionCreator.h index 65073ca5..ccc8ea59 100644 --- a/td/telegram/net/ConnectionCreator.h +++ b/td/telegram/net/ConnectionCreator.h @@ -48,6 +48,8 @@ class GetHostByNameActor; namespace td { +extern int VERBOSITY_NAME(connections); + class Proxy { public: static Proxy socks5(string server, int32 port, string user, string password) { diff --git a/tdutils/td/utils/OptionsParser.h b/tdutils/td/utils/OptionsParser.h index 6ac03855..c59c654a 100644 --- a/tdutils/td/utils/OptionsParser.h +++ b/tdutils/td/utils/OptionsParser.h @@ -57,7 +57,6 @@ class OptionsParser { #if TD_WINDOWS return -1; #else - // use getopt. long keys are not supported for now char buff[1024]; StringBuilder sb({buff, sizeof(buff)}); for (auto &opt : options_) {