Skip to content

Commit

Permalink
Log: sort categories by name (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo authored Jun 22, 2022
1 parent da2ebef commit a7d914f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,18 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
return false;
}

std::vector<CLogCategoryDesc> GetSortedCategories()
{
std::vector<CLogCategoryDesc> categories(LogCategories, LogCategories + std::size(LogCategories));
std::sort(categories.begin(), categories.end(), [](auto a, auto b) { return a.category < b.category; });
return categories;
}

std::string ListLogCategories()
{
std::string ret;
int outcount = 0;
for (const CLogCategoryDesc& category_desc : LogCategories) {
for (const CLogCategoryDesc& category_desc : GetSortedCategories()) {
// Omit the special cases.
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL) {
if (outcount != 0) ret += ", ";
Expand All @@ -195,7 +202,7 @@ std::string ListLogCategories()
std::vector<CLogCategoryActive> ListActiveLogCategories()
{
std::vector<CLogCategoryActive> ret;
for (const CLogCategoryDesc& category_desc : LogCategories) {
for (const CLogCategoryDesc& category_desc : GetSortedCategories()) {
// Omit the special cases.
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL) {
CLogCategoryActive catActive;
Expand Down

0 comments on commit a7d914f

Please sign in to comment.