log: Use Join() helper when listing log categories
This commit is contained in:
parent
79b0459648
commit
faec063887
4 changed files with 17 additions and 31 deletions
|
@ -520,7 +520,8 @@ void SetupServerArgs(NodeContext& node)
|
||||||
gArgs.AddArg("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
gArgs.AddArg("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||||
gArgs.AddArg("-addrmantest", "Allows to test address relay on localhost", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
gArgs.AddArg("-addrmantest", "Allows to test address relay on localhost", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||||
gArgs.AddArg("-debug=<category>", "Output debugging information (default: -nodebug, supplying <category> is optional). "
|
gArgs.AddArg("-debug=<category>", "Output debugging information (default: -nodebug, supplying <category> is optional). "
|
||||||
"If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + ListLogCategories() + ".", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
"If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + LogInstance().LogCategoriesString() + ".",
|
||||||
|
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||||
gArgs.AddArg("-debugexclude=<category>", strprintf("Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except one or more specified categories."), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
gArgs.AddArg("-debugexclude=<category>", strprintf("Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except one or more specified categories."), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||||
gArgs.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
gArgs.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||||
gArgs.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
gArgs.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||||
|
|
|
@ -182,30 +182,15 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ListLogCategories()
|
std::vector<LogCategory> BCLog::Logger::LogCategoriesList()
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::vector<LogCategory> ret;
|
||||||
int outcount = 0;
|
|
||||||
for (const CLogCategoryDesc& category_desc : LogCategories) {
|
for (const CLogCategoryDesc& category_desc : LogCategories) {
|
||||||
// Omit the special cases.
|
// Omit the special cases.
|
||||||
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL) {
|
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL) {
|
||||||
if (outcount != 0) ret += ", ";
|
LogCategory catActive;
|
||||||
ret += category_desc.category;
|
|
||||||
outcount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<CLogCategoryActive> ListActiveLogCategories()
|
|
||||||
{
|
|
||||||
std::vector<CLogCategoryActive> ret;
|
|
||||||
for (const CLogCategoryDesc& category_desc : LogCategories) {
|
|
||||||
// Omit the special cases.
|
|
||||||
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL) {
|
|
||||||
CLogCategoryActive catActive;
|
|
||||||
catActive.category = category_desc.category;
|
catActive.category = category_desc.category;
|
||||||
catActive.active = LogAcceptCategory(category_desc.flag);
|
catActive.active = WillLogCategory(category_desc.flag);
|
||||||
ret.push_back(catActive);
|
ret.push_back(catActive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
|
#include <util/string.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
@ -24,8 +25,7 @@ extern const char * const DEFAULT_DEBUGLOGFILE;
|
||||||
|
|
||||||
extern bool fLogIPs;
|
extern bool fLogIPs;
|
||||||
|
|
||||||
struct CLogCategoryActive
|
struct LogCategory {
|
||||||
{
|
|
||||||
std::string category;
|
std::string category;
|
||||||
bool active;
|
bool active;
|
||||||
};
|
};
|
||||||
|
@ -132,6 +132,13 @@ namespace BCLog {
|
||||||
bool DisableCategory(const std::string& str);
|
bool DisableCategory(const std::string& str);
|
||||||
|
|
||||||
bool WillLogCategory(LogFlags category) const;
|
bool WillLogCategory(LogFlags category) const;
|
||||||
|
/** Returns a vector of the log categories */
|
||||||
|
std::vector<LogCategory> LogCategoriesList();
|
||||||
|
/** Returns a string with the log categories */
|
||||||
|
std::string LogCategoriesString()
|
||||||
|
{
|
||||||
|
return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
|
||||||
|
};
|
||||||
|
|
||||||
bool DefaultShrinkDebugFile() const;
|
bool DefaultShrinkDebugFile() const;
|
||||||
};
|
};
|
||||||
|
@ -146,12 +153,6 @@ static inline bool LogAcceptCategory(BCLog::LogFlags category)
|
||||||
return LogInstance().WillLogCategory(category);
|
return LogInstance().WillLogCategory(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a string with the log categories. */
|
|
||||||
std::string ListLogCategories();
|
|
||||||
|
|
||||||
/** Returns a vector of the active log categories. */
|
|
||||||
std::vector<CLogCategoryActive> ListActiveLogCategories();
|
|
||||||
|
|
||||||
/** Return true if str parses as a log category and set the flag */
|
/** Return true if str parses as a log category and set the flag */
|
||||||
bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str);
|
bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str);
|
||||||
|
|
||||||
|
|
|
@ -516,7 +516,7 @@ UniValue logging(const JSONRPCRequest& request)
|
||||||
"When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
|
"When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
|
||||||
"The arguments are evaluated in order \"include\", \"exclude\".\n"
|
"The arguments are evaluated in order \"include\", \"exclude\".\n"
|
||||||
"If an item is both included and excluded, it will thus end up being excluded.\n"
|
"If an item is both included and excluded, it will thus end up being excluded.\n"
|
||||||
"The valid logging categories are: " + ListLogCategories() + "\n"
|
"The valid logging categories are: " + LogInstance().LogCategoriesString() + "\n"
|
||||||
"In addition, the following are available as category names with special meanings:\n"
|
"In addition, the following are available as category names with special meanings:\n"
|
||||||
" - \"all\", \"1\" : represent all logging categories.\n"
|
" - \"all\", \"1\" : represent all logging categories.\n"
|
||||||
" - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
|
" - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
|
||||||
|
@ -568,8 +568,7 @@ UniValue logging(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories();
|
for (const auto& logCatActive : LogInstance().LogCategoriesList()) {
|
||||||
for (const auto& logCatActive : vLogCatActive) {
|
|
||||||
result.pushKV(logCatActive.category, logCatActive.active);
|
result.pushKV(logCatActive.category, logCatActive.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue