|
8 | 8 | #include <util/threadnames.h>
|
9 | 9 | #include <util/time.h>
|
10 | 10 |
|
| 11 | +#include <algorithm> |
| 12 | +#include <array> |
| 13 | + |
11 | 14 | const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
|
12 | 15 |
|
13 | 16 | BCLog::Logger& LogInstance()
|
@@ -130,8 +133,7 @@ bool BCLog::Logger::DefaultShrinkDebugFile() const
|
130 | 133 | return m_categories == BCLog::NONE;
|
131 | 134 | }
|
132 | 135 |
|
133 |
| -struct CLogCategoryDesc |
134 |
| -{ |
| 136 | +struct CLogCategoryDesc { |
135 | 137 | BCLog::LogFlags flag;
|
136 | 138 | std::string category;
|
137 | 139 | };
|
@@ -201,16 +203,19 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
|
201 | 203 |
|
202 | 204 | std::vector<LogCategory> BCLog::Logger::LogCategoriesList(bool enabled_only) const
|
203 | 205 | {
|
| 206 | + // Sort log categories by alphabetical order. |
| 207 | + std::array<CLogCategoryDesc, std::size(LogCategories)> categories; |
| 208 | + std::copy(std::begin(LogCategories), std::end(LogCategories), categories.begin()); |
| 209 | + std::sort(categories.begin(), categories.end(), [](auto a, auto b) { return a.category < b.category; }); |
| 210 | + |
204 | 211 | std::vector<LogCategory> ret;
|
205 |
| - for (const CLogCategoryDesc& category_desc : LogCategories) { |
206 |
| - // Omit the special cases. |
207 |
| - if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL && category_desc.flag != BCLog::DASH) { |
208 |
| - LogCategory catActive; |
209 |
| - catActive.category = category_desc.category; |
210 |
| - catActive.active = WillLogCategory(category_desc.flag); |
211 |
| - if (!enabled_only || catActive.active) { |
212 |
| - ret.push_back(catActive); |
213 |
| - } |
| 212 | + for (const CLogCategoryDesc& category_desc : categories) { |
| 213 | + if (category_desc.flag == BCLog::NONE || category_desc.flag == BCLog::ALL || category_desc.flag == BCLog::DASH) continue; |
| 214 | + LogCategory catActive; |
| 215 | + catActive.category = category_desc.category; |
| 216 | + catActive.active = WillLogCategory(category_desc.flag); |
| 217 | + if (!enabled_only || catActive.active) { |
| 218 | + ret.push_back(catActive); |
214 | 219 | }
|
215 | 220 | }
|
216 | 221 | return ret;
|
@@ -261,7 +266,7 @@ namespace BCLog {
|
261 | 266 | }
|
262 | 267 | return ret;
|
263 | 268 | }
|
264 |
| -} |
| 269 | +} // namespace BCLog |
265 | 270 |
|
266 | 271 | void BCLog::Logger::LogPrintStr(const std::string& str)
|
267 | 272 | {
|
|
0 commit comments