diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 23ef943ed..03aa2bca2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3805,6 +3805,10 @@ setLogTagVerbosityLevel tag:string new_verbosity_level:int32 = Ok; //@description Returns current verbosity level for a specified TDLib internal log tag. This is an offline method. Can be called before authorization. Can be called synchronously @tag Logging tag to change verbosity level getLogTagVerbosityLevel tag:string = LogVerbosityLevel; +//@description Adds a message to TDLib internal log. This is an offline method. Can be called before authorization. Can be called synchronously +//@verbosity_level Minimum verbosity level needed for the message to be logged, 0-1023 @text Text of a message to log +addLogMessage verbosity_level:int32 text:string = Ok; + //@description Does nothing; for testing only. This is an offline method. Can be called before authorization testCallEmpty = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index d56eeccf0..bb97e5a04 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/Logging.cpp b/td/telegram/Logging.cpp index 8b9527b72..b91334795 100644 --- a/td/telegram/Logging.cpp +++ b/td/telegram/Logging.cpp @@ -130,4 +130,9 @@ Result Logging::get_tag_verbosity_level(Slice tag) { return *it->second; } +void Logging::add_message(int verbosity_level, Slice message) { + int VERBOSITY_NAME(client) = clamp(verbosity_level, 0, VERBOSITY_NAME(NEVER)); + VLOG(client) << message; +} + } // namespace td diff --git a/td/telegram/Logging.h b/td/telegram/Logging.h index 367bd3d47..ba92312c2 100644 --- a/td/telegram/Logging.h +++ b/td/telegram/Logging.h @@ -29,6 +29,8 @@ class Logging { static Status set_tag_verbosity_level(Slice tag, int new_verbosity_level); static Result get_tag_verbosity_level(Slice tag); + + static void add_message(int verbosity_level, Slice message); }; } // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 6e8c2ea59..20d4611dd 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3169,6 +3169,7 @@ bool Td::is_synchronous_request(int32 id) { case td_api::getLogTags::ID: case td_api::setLogTagVerbosityLevel::ID: case td_api::getLogTagVerbosityLevel::ID: + case td_api::addLogMessage::ID: return true; default: return false; @@ -7132,6 +7133,10 @@ void Td::on_request(uint64 id, const td_api::getLogTagVerbosityLevel &request) { UNREACHABLE(); } +void Td::on_request(uint64 id, const td_api::addLogMessage &request) { + UNREACHABLE(); +} + td_api::object_ptr Td::do_static_request(const td_api::getTextEntities &request) { if (!check_utf8(request.text_)) { return make_error(400, "Text must be encoded in UTF-8"); @@ -7266,6 +7271,11 @@ td_api::object_ptr Td::do_static_request(const td_api::getLogTag } } +td_api::object_ptr Td::do_static_request(const td_api::addLogMessage &request) { + Logging::add_message(request.verbosity_level_, request.text_); + return td_api::make_object(); +} + // test void Td::on_request(uint64 id, td_api::testNetwork &request) { create_handler(id)->send(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index a0252f344..52c78b71d 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -993,6 +993,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::getLogTagVerbosityLevel &request); + void on_request(uint64 id, const td_api::addLogMessage &request); + // test void on_request(uint64 id, td_api::testNetwork &request); void on_request(uint64 id, td_api::testGetDifference &request); @@ -1027,6 +1029,7 @@ class Td final : public NetQueryCallback { static td_api::object_ptr do_static_request(const td_api::getLogTags &request); static td_api::object_ptr do_static_request(const td_api::setLogTagVerbosityLevel &request); static td_api::object_ptr do_static_request(const td_api::getLogTagVerbosityLevel &request); + static td_api::object_ptr do_static_request(const td_api::addLogMessage &request); static DbKey as_db_key(string key); Status init(DbKey key) TD_WARN_UNUSED_RESULT; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index fc700fb25..d43129be1 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3651,6 +3651,17 @@ class CliClient final : public Actor { } else { execute(std::move(request)); } + } else if (op == "alog" || op == "aloge") { + string level; + string text; + std::tie(level, text) = split(args); + + auto request = td_api::make_object(to_integer(level), text); + if (op == "alog") { + send_request(std::move(request)); + } else { + execute(std::move(request)); + } } else if (op == "q" || op == "Quit") { quit(); } else if (op == "dnq" || op == "DumpNetQueries") {