diff options
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 88 |
1 files changed, 15 insertions, 73 deletions
diff --git a/src/util.cpp b/src/util.cpp index 280798f2fb..255226ea1e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -235,12 +235,12 @@ static void DebugPrintInit() mutexDebugLog = new boost::mutex(); } -int LogPrint(const char* category, const char* pszFormat, ...) +bool LogAcceptCategory(const char* category) { if (category != NULL) { if (!fDebug) - return 0; + return false; // Give each thread quick access to -debug settings. // This helps prevent issues debugging global destructors, @@ -258,17 +258,18 @@ int LogPrint(const char* category, const char* pszFormat, ...) // if not debugging everything and not debugging specific category, LogPrint does nothing. if (setCategories.count(string("")) == 0 && setCategories.count(string(category)) == 0) - return 0; + return false; } + return true; +} +int LogPrintStr(const std::string &str) +{ int ret = 0; // Returns total number of characters written if (fPrintToConsole) { // print to console - va_list arg_ptr; - va_start(arg_ptr, pszFormat); - ret += vprintf(pszFormat, arg_ptr); - va_end(arg_ptr); + ret = fwrite(str.data(), 1, str.size(), stdout); } else if (fPrintToDebugLog) { @@ -291,76 +292,17 @@ int LogPrint(const char* category, const char* pszFormat, ...) // Debug print useful for profiling if (fLogTimestamps && fStartedNewLine) ret += fprintf(fileout, "%s ", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()).c_str()); - if (pszFormat[strlen(pszFormat) - 1] == '\n') + if (!str.empty() && str[str.size()-1] == '\n') fStartedNewLine = true; else fStartedNewLine = false; - va_list arg_ptr; - va_start(arg_ptr, pszFormat); - ret += vfprintf(fileout, pszFormat, arg_ptr); - va_end(arg_ptr); + ret = fwrite(str.data(), 1, str.size(), fileout); } return ret; } -string vstrprintf(const char *format, va_list ap) -{ - char buffer[50000]; - char* p = buffer; - int limit = sizeof(buffer); - int ret; - while (true) - { - va_list arg_ptr; - va_copy(arg_ptr, ap); - ret = vsnprintf(p, limit, format, arg_ptr); - va_end(arg_ptr); - if (ret >= 0 && ret < limit) - break; - if (p != buffer) - delete[] p; - limit *= 2; - p = new char[limit]; - if (p == NULL) - throw std::bad_alloc(); - } - string str(p, p+ret); - if (p != buffer) - delete[] p; - return str; -} - -string real_strprintf(const char *format, int dummy, ...) -{ - va_list arg_ptr; - va_start(arg_ptr, dummy); - string str = vstrprintf(format, arg_ptr); - va_end(arg_ptr); - return str; -} - -string real_strprintf(const std::string &format, int dummy, ...) -{ - va_list arg_ptr; - va_start(arg_ptr, dummy); - string str = vstrprintf(format.c_str(), arg_ptr); - va_end(arg_ptr); - return str; -} - -bool error(const char *format, ...) -{ - va_list arg_ptr; - va_start(arg_ptr, format); - std::string str = vstrprintf(format, arg_ptr); - va_end(arg_ptr); - LogPrintf("ERROR: %s\n", str.c_str()); - return false; -} - - void ParseString(const string& str, char c, vector<string>& v) { if (str.empty()) @@ -1003,13 +945,13 @@ static std::string FormatException(std::exception* pex, const char* pszThread) void LogException(std::exception* pex, const char* pszThread) { std::string message = FormatException(pex, pszThread); - LogPrintf("\n%s", message.c_str()); + LogPrintf("\n%s", message); } void PrintException(std::exception* pex, const char* pszThread) { std::string message = FormatException(pex, pszThread); - LogPrintf("\n\n************************\n%s\n", message.c_str()); + LogPrintf("\n\n************************\n%s\n", message); fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); strMiscWarning = message; throw; @@ -1018,7 +960,7 @@ void PrintException(std::exception* pex, const char* pszThread) void PrintExceptionContinue(std::exception* pex, const char* pszThread) { std::string message = FormatException(pex, pszThread); - LogPrintf("\n\n************************\n%s\n", message.c_str()); + LogPrintf("\n\n************************\n%s\n", message); fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); strMiscWarning = message; } @@ -1363,7 +1305,7 @@ void AddTimeData(const CNetAddr& ip, int64_t nTime) fDone = true; string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly."); strMiscWarning = strMessage; - LogPrintf("*** %s\n", strMessage.c_str()); + LogPrintf("*** %s\n", strMessage); uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING); } } @@ -1466,7 +1408,7 @@ void runCommand(std::string strCommand) { int nErr = ::system(strCommand.c_str()); if (nErr) - LogPrintf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr); + LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr); } void RenameThread(const char* name) |