| 277 | } |
| 278 | |
| 279 | int LogPrintStr(const std::string &str) |
| 280 | { |
| 281 | int ret = 0; // Returns total number of characters written |
| 282 | static bool fStartedNewLine = true; |
| 283 | |
| 284 | string strTimestamped = LogTimestampStr(str, &fStartedNewLine); |
| 285 | |
| 286 | if (fPrintToConsole) |
| 287 | { |
| 288 | // print to console |
| 289 | ret = fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout); |
| 290 | fflush(stdout); |
| 291 | } |
| 292 | else if (fPrintToDebugLog) |
| 293 | { |
| 294 | boost::call_once(&DebugPrintInit, debugPrintInitFlag); |
| 295 | boost::mutex::scoped_lock scoped_lock(*mutexDebugLog); |
| 296 | |
| 297 | // buffer if we haven't opened the log yet |
| 298 | if (fileout == NULL) { |
| 299 | assert(vMsgsBeforeOpenLog); |
| 300 | ret = strTimestamped.length(); |
| 301 | vMsgsBeforeOpenLog->push_back(strTimestamped); |
| 302 | } |
| 303 | else |
| 304 | { |
| 305 | // reopen the log file, if requested |
| 306 | if (fReopenDebugLog) { |
| 307 | fReopenDebugLog = false; |
| 308 | boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; |
| 309 | if (freopen(pathDebug.string().c_str(),"a",fileout) != NULL) |
| 310 | setbuf(fileout, NULL); // unbuffered |
| 311 | } |
| 312 | |
| 313 | ret = FileWriteStr(strTimestamped, fileout); |
| 314 | } |
| 315 | } |
| 316 | return ret; |
| 317 | } |
| 318 | |
| 319 | /** Interpret string as boolean, for argument parsing */ |
| 320 | static bool InterpretBool(const std::string& strValue) |
no test coverage detected