mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-26 04:05:49 +01:00
Allow to change memory log verbosity level.
This commit is contained in:
parent
f781aab119
commit
a01c36ec1f
@ -146,7 +146,8 @@ int main(int argc, char *argv[]) {
|
|||||||
td::string http_ip_address = "0.0.0.0";
|
td::string http_ip_address = "0.0.0.0";
|
||||||
td::string http_stat_ip_address = "0.0.0.0";
|
td::string http_stat_ip_address = "0.0.0.0";
|
||||||
td::string log_file_path;
|
td::string log_file_path;
|
||||||
int verbosity_level = 0;
|
int default_verbosity_level = 0;
|
||||||
|
int memory_verbosity_level = VERBOSITY_NAME(INFO);
|
||||||
td::int64 log_max_file_size = 2000000000;
|
td::int64 log_max_file_size = 2000000000;
|
||||||
td::string working_directory;
|
td::string working_directory;
|
||||||
td::string temporary_directory;
|
td::string temporary_directory;
|
||||||
@ -225,7 +226,10 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
options.add_option('l', "log", "path to the file where the log will be written",
|
options.add_option('l', "log", "path to the file where the log will be written",
|
||||||
td::OptionParser::parse_string(log_file_path));
|
td::OptionParser::parse_string(log_file_path));
|
||||||
options.add_checked_option('v', "verbosity", "log verbosity level", td::OptionParser::parse_integer(verbosity_level));
|
options.add_checked_option('v', "verbosity", "log verbosity level",
|
||||||
|
td::OptionParser::parse_integer(default_verbosity_level));
|
||||||
|
options.add_checked_option('\0', "memory-verbosity", "memory log verbosity level; defaults to 3",
|
||||||
|
td::OptionParser::parse_integer(memory_verbosity_level));
|
||||||
options.add_checked_option(
|
options.add_checked_option(
|
||||||
'\0', "log-max-file-size",
|
'\0', "log-max-file-size",
|
||||||
PSLICE() << "maximum size of the log file in bytes before it will be auto-rotated (default is "
|
PSLICE() << "maximum size of the log file in bytes before it will be auto-rotated (default is "
|
||||||
@ -254,11 +258,17 @@ int main(int argc, char *argv[]) {
|
|||||||
return td::Status::OK();
|
return td::Status::OK();
|
||||||
});
|
});
|
||||||
options.add_check([&] {
|
options.add_check([&] {
|
||||||
if (verbosity_level < 0) {
|
if (default_verbosity_level < 0) {
|
||||||
return td::Status::Error("Wrong verbosity level specified");
|
return td::Status::Error("Wrong verbosity level specified");
|
||||||
}
|
}
|
||||||
return td::Status::OK();
|
return td::Status::OK();
|
||||||
});
|
});
|
||||||
|
options.add_check([&] {
|
||||||
|
if (memory_verbosity_level < 0) {
|
||||||
|
return td::Status::Error("Wrong memory verbosity level specified");
|
||||||
|
}
|
||||||
|
return td::Status::OK();
|
||||||
|
});
|
||||||
auto r_non_options = options.run(argc, argv, 0);
|
auto r_non_options = options.run(argc, argv, 0);
|
||||||
if (need_print_usage) {
|
if (need_print_usage) {
|
||||||
LOG(PLAIN) << options;
|
LOG(PLAIN) << options;
|
||||||
@ -379,14 +389,13 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
::td::VERBOSITY_NAME(dns_resolver) = VERBOSITY_NAME(WARNING);
|
::td::VERBOSITY_NAME(dns_resolver) = VERBOSITY_NAME(WARNING);
|
||||||
|
|
||||||
auto set_verbosity_level = [&log](int new_verbosity_level) {
|
log.set_second_verbosity_level(memory_verbosity_level);
|
||||||
int memory_verbosity_level = td::max(VERBOSITY_NAME(INFO), new_verbosity_level);
|
|
||||||
SET_VERBOSITY_LEVEL(memory_verbosity_level);
|
|
||||||
|
|
||||||
|
auto set_verbosity_level = [&log, memory_verbosity_level](int new_verbosity_level) {
|
||||||
|
SET_VERBOSITY_LEVEL(td::max(memory_verbosity_level, new_verbosity_level));
|
||||||
log.set_first_verbosity_level(new_verbosity_level);
|
log.set_first_verbosity_level(new_verbosity_level);
|
||||||
log.set_second_verbosity_level(memory_verbosity_level);
|
|
||||||
};
|
};
|
||||||
set_verbosity_level(verbosity_level);
|
set_verbosity_level(default_verbosity_level);
|
||||||
|
|
||||||
// LOG(WARNING) << "Bot API server with commit " << td::GitInfo::commit() << ' '
|
// LOG(WARNING) << "Bot API server with commit " << td::GitInfo::commit() << ' '
|
||||||
// << (td::GitInfo::is_dirty() ? "(dirty)" : "") << " started";
|
// << (td::GitInfo::is_dirty() ? "(dirty)" : "") << " started";
|
||||||
@ -458,12 +467,12 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!need_change_verbosity_level.test_and_set()) {
|
if (!need_change_verbosity_level.test_and_set()) {
|
||||||
if (log.get_first_verbosity_level() == verbosity_level) {
|
if (log.get_first_verbosity_level() == default_verbosity_level) {
|
||||||
// increase default log verbosity level
|
// increase default log verbosity level
|
||||||
set_verbosity_level(100);
|
set_verbosity_level(100);
|
||||||
} else {
|
} else {
|
||||||
// return back verbosity level
|
// return back verbosity level
|
||||||
set_verbosity_level(verbosity_level);
|
set_verbosity_level(default_verbosity_level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user