[FAQ] What are debug messages and how are they programmed in Feathercoin?
-
[FAQ] What are debug messages and how are they programmed in Feathercoin?
The Feathercoin blockchain and wallet software contains a number of error reporting systems.
Unnecessary writing to disk, or doing tests for a condition slow the program down and is inefficient. It is the major source of user issues, by 10 times, for FTC moderators to deal with.
LogPrint()
LogPrint("rpc", "RPC stopped.\n");
This is the correct format for a useful message to be included in -debug or .feathercoin/debug.log (GNU/Linux) output. It should not be place in tight loops, usually only when an unusual condition is triggered.
It is defined in
util.h
/** 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)) \
e.g. local database is corrupt or some such that might be usefull to a user or support.
The problem programmers have with this is, you need to define “category”, ie slightly complected structure of pass parameters). Only suitable one program is written.
LogPrintf()
// if (fDebug) LogPrintf("Importing blocks file %s...\n", path.string());
This is meant for programmers to use during the writing or updating of the source code. It should be commented out or removed once the code is operating.
If you are working on a section of code, or Alpha testing a new feature, search and replace the comments out to output the state of local parameters to the debug.log.
Due to the issue of non removal of debug log and debug testing,
-
if (Debug) should be added to all coding console and log messages.
-
All LogPrintf() messages should be commented out in production code and only uncommented in a test version / build of the software.
if (fDebug)
If there is a longer term issue or test then (fDebug) can be used, this is true if -debug is set.
How fDebug is set in FTC 0.9.6.2 :
init.cpp
fDebug = !mapMultiArgs["-debug"].empty(); // Special-case: if -debug=0/-nodebug is set, turn off debugging messages const vector<string>& categories = mapMultiArgs["-debug"]; if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), string("0")) != categories.end()) fDebug = false;
return error(“message”, etc)
A function can return an error, these are printed to the debug.log. Some of these conditions, originally envisioned as rare, have been found to occur, in this case the massage should be removed from error and made debug specific as necessary.
printf()
An example of printf() from neoscypt C code.
printf("BLAKE2s integrity test failed!\n");
From stealth in rpcwallet.cpp
printf("Found %u stealth transactions in blockchain.\n", pwalletMain->nStealth);
qDebug()
qDebug() << “PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates”;
Qt reporting system, writes to debug.log
qWarning()
From transactionmodel.cpp
qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet";
Qt reporting system, writes to debug.log
strprintf()
strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
fprintf()
if (fLogTimestamps && fStartedNewLine) ret += fprintf(fileout, "%s ", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()).c_str());
CNetAddr::print()
In netbase.cpp
void CNetAddr::print() const { LogPrintf("CNetAddr(%s)\n", ToString()); }
CService::print()
In netbase.cpp
void CService::print() const { LogPrintf("CService(%s)\n", ToString()); }
-