From 801dbc8f6f1210a96a9a91416b6f57294c8d3573 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 13 Apr 2019 21:40:31 +0300 Subject: [PATCH] Add td_api::addLogMessage. GitOrigin-RevId: 7ad16cacd59eef90bcd5f55729847d4699bbff64 --- td/generate/scheme/td_api.tl | 4 ++++ td/generate/scheme/td_api.tlo | Bin 150808 -> 150936 bytes td/telegram/Logging.cpp | 5 +++++ td/telegram/Logging.h | 2 ++ td/telegram/Td.cpp | 10 ++++++++++ td/telegram/Td.h | 3 +++ td/telegram/cli.cpp | 11 +++++++++++ 7 files changed, 35 insertions(+) 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 d56eeccf0ab99a5708a8799b02a51ceb7b60e1c7..bb97e5a0471803b0cbf455c1afee33b8aaec1af6 100644 GIT binary patch delta 69 zcmV-L0J{H}nhBVj34pW#jH&@kw~eX+^8*p=&o*BTVPs@XZ)Z(qb8}&5mw`P36O%B? bB$p6R0R@xIcMp!gd0D^J~uK)l5 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") {