Add td_api::addLogMessage.

GitOrigin-RevId: 7ad16cacd59eef90bcd5f55729847d4699bbff64
This commit is contained in:
levlam 2019-04-13 21:40:31 +03:00
parent c4cafa9456
commit 801dbc8f6f
7 changed files with 35 additions and 0 deletions

View File

@ -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;

Binary file not shown.

View File

@ -130,4 +130,9 @@ Result<int> 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

View File

@ -29,6 +29,8 @@ class Logging {
static Status set_tag_verbosity_level(Slice tag, int new_verbosity_level);
static Result<int> get_tag_verbosity_level(Slice tag);
static void add_message(int verbosity_level, Slice message);
};
} // namespace td

View File

@ -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_api::Object> 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_api::Object> Td::do_static_request(const td_api::getLogTag
}
}
td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::addLogMessage &request) {
Logging::add_message(request.verbosity_level_, request.text_);
return td_api::make_object<td_api::ok>();
}
// test
void Td::on_request(uint64 id, td_api::testNetwork &request) {
create_handler<TestQuery>(id)->send();

View File

@ -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<td_api::Object> do_static_request(const td_api::getLogTags &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::setLogTagVerbosityLevel &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getLogTagVerbosityLevel &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::addLogMessage &request);
static DbKey as_db_key(string key);
Status init(DbKey key) TD_WARN_UNUSED_RESULT;

View File

@ -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<td_api::addLogMessage>(to_integer<int32>(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") {