|
|
@ -12,6 +12,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "compat.h" |
|
|
|
#include "compat.h" |
|
|
|
#include "serialize.h" |
|
|
|
#include "serialize.h" |
|
|
|
|
|
|
|
#include "tinyformat.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <cstdio> |
|
|
|
#include <cstdio> |
|
|
|
#include <exception> |
|
|
|
#include <exception> |
|
|
@ -99,21 +100,6 @@ inline void MilliSleep(int64_t n) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* This GNU C extension enables the compiler to check the format string against the parameters provided.
|
|
|
|
|
|
|
|
* X is the number of the "format string" parameter, and Y is the number of the first variadic parameter. |
|
|
|
|
|
|
|
* Parameters count from 1. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
#ifdef __GNUC__ |
|
|
|
|
|
|
|
#define ATTR_WARN_PRINTF(X,Y) __attribute__((format(gnu_printf,X,Y))) |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
#define ATTR_WARN_PRINTF(X,Y) |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern std::map<std::string, std::string> mapArgs; |
|
|
|
extern std::map<std::string, std::string> mapArgs; |
|
|
@ -130,27 +116,49 @@ extern volatile bool fReopenDebugLog; |
|
|
|
void RandAddSeed(); |
|
|
|
void RandAddSeed(); |
|
|
|
void RandAddSeedPerfmon(); |
|
|
|
void RandAddSeedPerfmon(); |
|
|
|
|
|
|
|
|
|
|
|
// Print to debug.log if -debug=category switch is given OR category is NULL.
|
|
|
|
/* Return true if log accepts specified category */ |
|
|
|
int ATTR_WARN_PRINTF(2,3) LogPrint(const char* category, const char* pszFormat, ...); |
|
|
|
bool LogAcceptCategory(const char* category); |
|
|
|
|
|
|
|
/* Send a string to the log output */ |
|
|
|
|
|
|
|
int LogPrintStr(const std::string &str); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define strprintf tfm::format |
|
|
|
#define LogPrintf(...) LogPrint(NULL, __VA_ARGS__) |
|
|
|
#define LogPrintf(...) LogPrint(NULL, __VA_ARGS__) |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/* When we switch to C++11, this can be switched to variadic templates instead
|
|
|
|
Rationale for the real_strprintf / strprintf construction: |
|
|
|
* of this macro-based construction (see tinyformat.h). |
|
|
|
It is not allowed to use va_start with a pass-by-reference argument. |
|
|
|
*/ |
|
|
|
(C++ standard, 18.7, paragraph 3). Use a dummy argument to work around this, and use a |
|
|
|
#define MAKE_ERROR_AND_LOG_FUNC(n) \ |
|
|
|
macro to keep similar semantics. |
|
|
|
/* Print to debug.log if -debug=category switch is given OR category is NULL. */ \ |
|
|
|
*/ |
|
|
|
template<TINYFORMAT_ARGTYPES(n)> \ |
|
|
|
|
|
|
|
static inline int LogPrint(const char* category, const char* format, TINYFORMAT_VARARGS(n)) \ |
|
|
|
/** Overload strprintf for char*, so that GCC format type warnings can be given */ |
|
|
|
{ \ |
|
|
|
std::string ATTR_WARN_PRINTF(1,3) real_strprintf(const char *format, int dummy, ...); |
|
|
|
if(!LogAcceptCategory(category)) return 0; \ |
|
|
|
/** Overload strprintf for std::string, to be able to use it with _ (translation).
|
|
|
|
return LogPrintStr(tfm::format(format, TINYFORMAT_PASSARGS(n))); \ |
|
|
|
* This will not support GCC format type warnings (-Wformat) so be careful. |
|
|
|
} \ |
|
|
|
|
|
|
|
/* Log error and return false */ \ |
|
|
|
|
|
|
|
template<TINYFORMAT_ARGTYPES(n)> \ |
|
|
|
|
|
|
|
static inline bool error(const char* format, TINYFORMAT_VARARGS(n)) \ |
|
|
|
|
|
|
|
{ \ |
|
|
|
|
|
|
|
LogPrintStr("ERROR: " + tfm::format(format, TINYFORMAT_PASSARGS(n))); \ |
|
|
|
|
|
|
|
return false; \ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TINYFORMAT_FOREACH_ARGNUM(MAKE_ERROR_AND_LOG_FUNC) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Zero-arg versions of logging and error, these are not covered by
|
|
|
|
|
|
|
|
* TINYFORMAT_FOREACH_ARGNUM |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
std::string real_strprintf(const std::string &format, int dummy, ...); |
|
|
|
static inline int LogPrint(const char* category, const char* format) |
|
|
|
#define strprintf(format, ...) real_strprintf(format, 0, __VA_ARGS__) |
|
|
|
{ |
|
|
|
std::string vstrprintf(const char *format, va_list ap); |
|
|
|
if(!LogAcceptCategory(category)) return 0; |
|
|
|
|
|
|
|
return LogPrintStr(format); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
static inline bool error(const char* format) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrintStr(std::string("ERROR: ") + format); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LogException(std::exception* pex, const char* pszThread); |
|
|
|
void LogException(std::exception* pex, const char* pszThread); |
|
|
|
void PrintException(std::exception* pex, const char* pszThread); |
|
|
|
void PrintException(std::exception* pex, const char* pszThread); |
|
|
|