|
8 | 8 | #include <util/string.h>
|
9 | 9 | #include <util/time.h>
|
10 | 10 |
|
| 11 | +#include <algorithm> |
| 12 | +#include <array> |
11 | 13 | #include <mutex>
|
12 | 14 |
|
13 | 15 | const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
|
@@ -124,8 +126,7 @@ bool BCLog::Logger::DefaultShrinkDebugFile() const
|
124 | 126 | return m_categories == BCLog::NONE;
|
125 | 127 | }
|
126 | 128 |
|
127 |
| -struct CLogCategoryDesc |
128 |
| -{ |
| 129 | +struct CLogCategoryDesc { |
129 | 130 | BCLog::LogFlags flag;
|
130 | 131 | std::string category;
|
131 | 132 | };
|
@@ -179,15 +180,18 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
|
179 | 180 |
|
180 | 181 | std::vector<LogCategory> BCLog::Logger::LogCategoriesList() const
|
181 | 182 | {
|
| 183 | + // Sort log categories by alphabetical order. |
| 184 | + std::array<CLogCategoryDesc, std::size(LogCategories)> categories; |
| 185 | + std::copy(std::begin(LogCategories), std::end(LogCategories), categories.begin()); |
| 186 | + std::sort(categories.begin(), categories.end(), [](auto a, auto b) { return a.category < b.category; }); |
| 187 | + |
182 | 188 | std::vector<LogCategory> ret;
|
183 |
| - for (const CLogCategoryDesc& category_desc : LogCategories) { |
184 |
| - // Omit the special cases. |
185 |
| - if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL) { |
186 |
| - LogCategory catActive; |
187 |
| - catActive.category = category_desc.category; |
188 |
| - catActive.active = WillLogCategory(category_desc.flag); |
189 |
| - ret.push_back(catActive); |
190 |
| - } |
| 189 | + for (const CLogCategoryDesc& category_desc : categories) { |
| 190 | + if (category_desc.flag == BCLog::NONE || category_desc.flag == BCLog::ALL) continue; |
| 191 | + LogCategory catActive; |
| 192 | + catActive.category = category_desc.category; |
| 193 | + catActive.active = WillLogCategory(category_desc.flag); |
| 194 | + ret.push_back(catActive); |
191 | 195 | }
|
192 | 196 | return ret;
|
193 | 197 | }
|
@@ -237,7 +241,7 @@ namespace BCLog {
|
237 | 241 | }
|
238 | 242 | return ret;
|
239 | 243 | }
|
240 |
| -} |
| 244 | +} // namespace BCLog |
241 | 245 |
|
242 | 246 | void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, const int source_line)
|
243 | 247 | {
|
|
0 commit comments