Skip to content

Commit bd971bf

Browse files
committed
logging: Unconditionally log levels >= WARN
Messages with level `WARN` or higher should be logged even when the category is not provided with `-debug=`, to make sure important warnings are not lost.
1 parent 90e49c1 commit bd971bf

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/dbwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CBitcoinLevelDBLogger : public leveldb::Logger {
1919
// This code is adapted from posix_logger.h, which is why it is using vsprintf.
2020
// Please do not do this in normal code
2121
void Logv(const char * format, va_list ap) override {
22-
if (!LogAcceptCategory(BCLog::LEVELDB)) {
22+
if (!LogAcceptCategory(BCLog::LEVELDB, BCLog::Level::Debug)) {
2323
return;
2424
}
2525
char buffer[500];
@@ -186,7 +186,7 @@ CDBWrapper::~CDBWrapper()
186186

187187
bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
188188
{
189-
const bool log_memory = LogAcceptCategory(BCLog::LEVELDB);
189+
const bool log_memory = LogAcceptCategory(BCLog::LEVELDB, BCLog::Level::Debug);
190190
double mem_before = 0;
191191
if (log_memory) {
192192
mem_before = DynamicMemoryUsage() / 1024.0 / 1024;

src/logging.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,14 @@ namespace BCLog {
166166

167167
BCLog::Logger& LogInstance();
168168

169-
/** Return true if log accepts specified category */
170-
static inline bool LogAcceptCategory(BCLog::LogFlags category)
169+
/** Return true if log accepts specified category, at the specified level. */
170+
static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level)
171171
{
172+
// Log messages at Warning and Error level unconditionally, so that
173+
// important troubleshooting information doesn't get lost.
174+
if (level >= BCLog::Level::Warning) {
175+
return true;
176+
}
172177
return LogInstance().WillLogCategory(category);
173178
}
174179

@@ -203,14 +208,14 @@ static inline void LogPrintf_(const std::string& logging_function, const std::st
203208
// evaluating arguments when logging for the category is not enabled.
204209
#define LogPrint(category, ...) \
205210
do { \
206-
if (LogAcceptCategory((category))) { \
211+
if (LogAcceptCategory((category), BCLog::Level::Debug)) { \
207212
LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__); \
208213
} \
209214
} while (0)
210215

211216
#define LogPrintLevel(level, category, ...) \
212217
do { \
213-
if (LogAcceptCategory((category))) { \
218+
if (LogAcceptCategory((category), (level))) { \
214219
LogPrintLevel_(category, level, __VA_ARGS__); \
215220
} \
216221
} while (0)

src/timedata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
9999
}
100100
}
101101

102-
if (LogAcceptCategory(BCLog::NET)) {
102+
if (LogAcceptCategory(BCLog::NET, BCLog::Level::Debug)) {
103103
std::string log_message{"time data samples: "};
104104
for (const int64_t n : vSorted) {
105105
log_message += strprintf("%+d ", n);

src/wallet/coinselection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ std::optional<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups,
307307
}
308308
}
309309

310-
if (LogAcceptCategory(BCLog::SELECTCOINS)) {
310+
if (LogAcceptCategory(BCLog::SELECTCOINS, BCLog::Level::Debug)) {
311311
std::string log_message{"Coin selection best subset: "};
312312
for (unsigned int i = 0; i < applicable_groups.size(); i++) {
313313
if (vfBest[i]) {

0 commit comments

Comments
 (0)