Skip to content

Commit 2b62551

Browse files
committed
Merge pull request #6881
7bbc7c3 Add option for microsecond precision in debug.log (Suhas Daftuar)
2 parents 7939164 + 7bbc7c3 commit 2b62551

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

src/init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ std::string HelpMessage(HelpMessageMode mode)
431431
strUsage += HelpMessageOpt("-logtimestamps", strprintf(_("Prepend debug output with timestamp (default: %u)"), 1));
432432
if (showDebug)
433433
{
434+
strUsage += HelpMessageOpt("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS));
434435
strUsage += HelpMessageOpt("-limitfreerelay=<n>", strprintf("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default: %u)", 15));
435436
strUsage += HelpMessageOpt("-relaypriority", strprintf("Require high priority for relaying free or low-fee transactions (default: %u)", 1));
436437
strUsage += HelpMessageOpt("-maxsigcachesize=<n>", strprintf("Limit size of signature cache to <n> entries (default: %u)", 50000));
@@ -728,6 +729,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
728729
// Set this early so that parameter interactions go to console
729730
fPrintToConsole = GetBoolArg("-printtoconsole", false);
730731
fLogTimestamps = GetBoolArg("-logtimestamps", true);
732+
fLogTimeMicros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
731733
fLogIPs = GetBoolArg("-logips", false);
732734

733735
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

src/util.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ bool fDaemon = false;
108108
bool fServer = false;
109109
string strMiscWarning;
110110
bool fLogTimestamps = false;
111+
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
111112
bool fLogIPs = false;
112113
volatile bool fReopenDebugLog = false;
113114
CTranslationInterface translationInterface;
@@ -263,9 +264,13 @@ static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine
263264
if (!fLogTimestamps)
264265
return str;
265266

266-
if (*fStartedNewLine)
267-
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()) + ' ' + str;
268-
else
267+
if (*fStartedNewLine) {
268+
int64_t nTimeMicros = GetLogTimeMicros();
269+
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000);
270+
if (fLogTimeMicros)
271+
strStamped += strprintf(".%06d", nTimeMicros%1000000);
272+
strStamped += ' ' + str;
273+
} else
269274
strStamped = str;
270275

271276
if (!str.empty() && str[str.size()-1] == '\n')

src/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <boost/signals2/signal.hpp>
2929
#include <boost/thread/exceptions.hpp>
3030

31+
static const bool DEFAULT_LOGTIMEMICROS = false;
32+
3133
/** Signals for translation. */
3234
class CTranslationInterface
3335
{
@@ -44,6 +46,7 @@ extern bool fPrintToDebugLog;
4446
extern bool fServer;
4547
extern std::string strMiscWarning;
4648
extern bool fLogTimestamps;
49+
extern bool fLogTimeMicros;
4750
extern bool fLogIPs;
4851
extern volatile bool fReopenDebugLog;
4952
extern CTranslationInterface translationInterface;

src/utiltime.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ int64_t GetTimeMicros()
4040
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
4141
}
4242

43+
/** Return a time useful for the debug log */
44+
int64_t GetLogTimeMicros()
45+
{
46+
if (nMockTime) return nMockTime*1000000;
47+
48+
return GetTimeMicros();
49+
}
50+
4351
void MilliSleep(int64_t n)
4452
{
4553

src/utiltime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
int64_t GetTime();
1313
int64_t GetTimeMillis();
1414
int64_t GetTimeMicros();
15+
int64_t GetLogTimeMicros();
1516
void SetMockTime(int64_t nMockTimeIn);
1617
void MilliSleep(int64_t n);
1718

0 commit comments

Comments
 (0)