aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2011-03-16 15:42:04 -0400
committerJeff Garzik <jgarzik@pobox.com>2011-03-16 15:42:04 -0400
commite2e5f5cd9da7d5a4d54a8c3fb3981ba82accc78e (patch)
treec794c4dc440471f32041b6e3b30c10dc4689d887
parent27b7f3b43a3868cd4d4f97e03c35074c2ef12349 (diff)
Fix -logtimestamps to only print time prefix once per output line
Incorporate BlueMatt's fix to only timestamp upon new line, and move -logtimestamp checking outside OutputDebugPrintF() to better future-proof it.
-rw-r--r--init.cpp2
-rw-r--r--util.cpp10
-rw-r--r--util.h1
3 files changed, 11 insertions, 2 deletions
diff --git a/init.cpp b/init.cpp
index 3afc8eedc9..8e58126693 100644
--- a/init.cpp
+++ b/init.cpp
@@ -211,8 +211,8 @@ bool AppInit2(int argc, char* argv[])
fPrintToDebugger = GetBoolArg("-printtodebugger");
fTestNet = GetBoolArg("-testnet");
-
fNoListen = GetBoolArg("-nolisten");
+ fLogTimestamps = GetBoolArg("-logtimestamps");
for (int i = 1; i < argc; i++)
if (!IsSwitchChar(argv[i][0]))
diff --git a/util.cpp b/util.cpp
index 26f8e0ac21..655626dd3b 100644
--- a/util.cpp
+++ b/util.cpp
@@ -19,6 +19,7 @@ bool fCommandLine = false;
string strMiscWarning;
bool fTestNet = false;
bool fNoListen = false;
+bool fLogTimestamps = false;
@@ -170,9 +171,16 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
}
if (fileout)
{
+ static bool fStartedNewLine = true;
+
// Debug print useful for profiling
- if (GetBoolArg("-logtimestamps"))
+ if (fLogTimestamps && fStartedNewLine)
fprintf(fileout, "%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
+ if (pszFormat[strlen(pszFormat) - 1] == '\n')
+ fStartedNewLine = true;
+ else
+ fStartedNewLine = false;
+
va_list arg_ptr;
va_start(arg_ptr, pszFormat);
ret = vfprintf(fileout, pszFormat, arg_ptr);
diff --git a/util.h b/util.h
index 1b780d5520..2a7dbb5107 100644
--- a/util.h
+++ b/util.h
@@ -148,6 +148,7 @@ extern bool fCommandLine;
extern string strMiscWarning;
extern bool fTestNet;
extern bool fNoListen;
+extern bool fLogTimestamps;
void RandAddSeed();
void RandAddSeedPerfmon();