Skip to content

Commit 7c57297

Browse files
committed
log: sort LogCategoriesList and LogCategoriesString alphabetically
1 parent f720cfa commit 7c57297

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/logging.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <util/string.h>
99
#include <util/time.h>
1010

11+
#include <algorithm>
12+
#include <array>
1113
#include <mutex>
1214

1315
const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
@@ -179,8 +181,13 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
179181

180182
std::vector<LogCategory> BCLog::Logger::LogCategoriesList() const
181183
{
184+
// Sort log categories by alphabetical order.
185+
std::array<CLogCategoryDesc, std::size(LogCategories)> categories;
186+
std::copy(std::begin(LogCategories), std::end(LogCategories), categories.begin());
187+
std::sort(categories.begin(), categories.end(), [](auto a, auto b) { return a.category < b.category; });
188+
182189
std::vector<LogCategory> ret;
183-
for (const CLogCategoryDesc& category_desc : LogCategories) {
190+
for (const CLogCategoryDesc& category_desc : categories) {
184191
// Omit the special cases.
185192
if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL) {
186193
LogCategory catActive;

src/logging.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ namespace BCLog {
138138
bool DisableCategory(const std::string& str);
139139

140140
bool WillLogCategory(LogFlags category) const;
141-
/** Returns a vector of the log categories */
141+
/** Returns a vector of the log categories in alphabetical order. */
142142
std::vector<LogCategory> LogCategoriesList() const;
143-
/** Returns a string with the log categories */
143+
/** Returns a string with the log categories in alphabetical order. */
144144
std::string LogCategoriesString() const
145145
{
146146
return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });

0 commit comments

Comments
 (0)