5
5
6
6
#include < logging.h>
7
7
#include < util.h>
8
- #include < utilstrencodings.h>
9
8
10
9
const char * const DEFAULT_DEBUGLOGFILE = " debug.log" ;
11
10
@@ -64,11 +63,27 @@ void BCLog::Logger::EnableCategory(BCLog::LogFlags flag)
64
63
logCategories |= flag;
65
64
}
66
65
66
+ bool BCLog::Logger::EnableCategory (const std::string& str)
67
+ {
68
+ BCLog::LogFlags flag;
69
+ if (!GetLogCategory (flag, str)) return false ;
70
+ EnableCategory (flag);
71
+ return true ;
72
+ }
73
+
67
74
void BCLog::Logger::DisableCategory (BCLog::LogFlags flag)
68
75
{
69
76
logCategories &= ~flag;
70
77
}
71
78
79
+ bool BCLog::Logger::DisableCategory (const std::string& str)
80
+ {
81
+ BCLog::LogFlags flag;
82
+ if (!GetLogCategory (flag, str)) return false ;
83
+ DisableCategory (flag);
84
+ return true ;
85
+ }
86
+
72
87
bool BCLog::Logger::WillLogCategory (BCLog::LogFlags category) const
73
88
{
74
89
return (logCategories.load (std::memory_order_relaxed) & category) != 0 ;
@@ -81,7 +96,7 @@ bool BCLog::Logger::DefaultShrinkDebugFile() const
81
96
82
97
struct CLogCategoryDesc
83
98
{
84
- uint32_t flag;
99
+ BCLog::LogFlags flag;
85
100
std::string category;
86
101
};
87
102
@@ -114,19 +129,17 @@ const CLogCategoryDesc LogCategories[] =
114
129
{BCLog::ALL, " all" },
115
130
};
116
131
117
- bool GetLogCategory (uint32_t *f , const std::string * str)
132
+ bool GetLogCategory (BCLog::LogFlags& flag , const std::string& str)
118
133
{
119
- if (f && str) {
120
- if (*str == " " ) {
121
- *f = BCLog::ALL;
134
+ if (str == " " ) {
135
+ flag = BCLog::ALL;
136
+ return true ;
137
+ }
138
+ for (const CLogCategoryDesc& category_desc : LogCategories) {
139
+ if (category_desc.category == str) {
140
+ flag = category_desc.flag ;
122
141
return true ;
123
142
}
124
- for (unsigned int i = 0 ; i < ARRAYLEN (LogCategories); i++) {
125
- if (LogCategories[i].category == *str) {
126
- *f = LogCategories[i].flag ;
127
- return true ;
128
- }
129
- }
130
143
}
131
144
return false ;
132
145
}
@@ -135,11 +148,11 @@ std::string ListLogCategories()
135
148
{
136
149
std::string ret;
137
150
int outcount = 0 ;
138
- for (unsigned int i = 0 ; i < ARRAYLEN ( LogCategories); i++ ) {
151
+ for (const CLogCategoryDesc& category_desc : LogCategories) {
139
152
// Omit the special cases.
140
- if (LogCategories[i] .flag != BCLog::NONE && LogCategories[i] .flag != BCLog::ALL) {
153
+ if (category_desc .flag != BCLog::NONE && category_desc .flag != BCLog::ALL) {
141
154
if (outcount != 0 ) ret += " , " ;
142
- ret += LogCategories[i] .category ;
155
+ ret += category_desc .category ;
143
156
outcount++;
144
157
}
145
158
}
@@ -149,12 +162,12 @@ std::string ListLogCategories()
149
162
std::vector<CLogCategoryActive> ListActiveLogCategories ()
150
163
{
151
164
std::vector<CLogCategoryActive> ret;
152
- for (unsigned int i = 0 ; i < ARRAYLEN ( LogCategories); i++ ) {
165
+ for (const CLogCategoryDesc& category_desc : LogCategories) {
153
166
// Omit the special cases.
154
- if (LogCategories[i] .flag != BCLog::NONE && LogCategories[i] .flag != BCLog::ALL) {
167
+ if (category_desc .flag != BCLog::NONE && category_desc .flag != BCLog::ALL) {
155
168
CLogCategoryActive catActive;
156
- catActive.category = LogCategories[i] .category ;
157
- catActive.active = LogAcceptCategory (LogCategories[i] .flag );
169
+ catActive.category = category_desc .category ;
170
+ catActive.active = LogAcceptCategory (category_desc .flag );
158
171
ret.push_back (catActive);
159
172
}
160
173
}
0 commit comments