2020-10-09 08:30:51 -07:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
|
|
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
2022-05-11 15:47:12 -07:00
|
|
|
// Copyright (c) 2018-2022 The Zcash developers
|
2020-10-09 08:30:51 -07:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2020-12-12 16:33:22 -08:00
|
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2020-10-09 08:30:51 -07:00
|
|
|
|
|
|
|
#ifndef ZCASH_LOGGING_H
|
|
|
|
#define ZCASH_LOGGING_H
|
|
|
|
|
2017-03-01 07:54:22 -08:00
|
|
|
#include "fs.h"
|
2020-10-09 08:30:51 -07:00
|
|
|
#include "tinyformat.h"
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <tracing.h>
|
|
|
|
|
|
|
|
static const bool DEFAULT_LOGTIMEMICROS = false;
|
|
|
|
static const bool DEFAULT_LOGIPS = false;
|
|
|
|
static const bool DEFAULT_LOGTIMESTAMPS = true;
|
|
|
|
extern const char * const DEFAULT_DEBUGLOGFILE;
|
|
|
|
|
|
|
|
extern bool fPrintToConsole;
|
|
|
|
extern bool fPrintToDebugLog;
|
|
|
|
|
|
|
|
extern bool fLogTimestamps;
|
|
|
|
extern bool fLogIPs;
|
|
|
|
extern std::atomic<bool> fReopenDebugLog;
|
|
|
|
|
|
|
|
/** Returns the filtering directive set by the -debug flags. */
|
|
|
|
std::string LogConfigFilter();
|
|
|
|
|
|
|
|
/** Return true if log accepts specified category */
|
|
|
|
bool LogAcceptCategory(const char* category);
|
|
|
|
|
2022-08-16 10:27:41 -07:00
|
|
|
/** Print to debug log with level INFO and category "main". */
|
2020-10-09 08:30:51 -07:00
|
|
|
#define LogPrintf(...) LogPrintInner("info", "main", __VA_ARGS__)
|
|
|
|
|
2022-08-16 10:27:41 -07:00
|
|
|
/** Print to debug log with level DEBUG. */
|
2020-10-09 08:30:51 -07:00
|
|
|
#define LogPrint(category, ...) LogPrintInner("debug", category, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define LogPrintInner(level, category, ...) do { \
|
|
|
|
std::string T_MSG = tfm::format(__VA_ARGS__); \
|
|
|
|
if (!T_MSG.empty() && T_MSG[T_MSG.size()-1] == '\n') { \
|
|
|
|
T_MSG.erase(T_MSG.size()-1); \
|
|
|
|
} \
|
|
|
|
TracingLog(level, category, T_MSG.c_str()); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define LogError(category, ...) ([&]() { \
|
|
|
|
std::string T_MSG = tfm::format(__VA_ARGS__); \
|
|
|
|
TracingError(category, T_MSG.c_str()); \
|
|
|
|
return false; \
|
|
|
|
}())
|
|
|
|
|
2017-03-01 08:05:50 -08:00
|
|
|
fs::path GetDebugLogPath();
|
2020-10-09 08:30:51 -07:00
|
|
|
void ShrinkDebugFile();
|
|
|
|
|
|
|
|
#endif // ZCASH_LOGGING_H
|