Browse Source

Add option for microsecond precision in debug.log

0.13
Suhas Daftuar 9 years ago
parent
commit
7bbc7c314f
  1. 2
      src/init.cpp
  2. 11
      src/util.cpp
  3. 3
      src/util.h
  4. 8
      src/utiltime.cpp
  5. 1
      src/utiltime.h

2
src/init.cpp

@ -428,6 +428,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-logtimestamps", strprintf(_("Prepend debug output with timestamp (default: %u)"), 1)); strUsage += HelpMessageOpt("-logtimestamps", strprintf(_("Prepend debug output with timestamp (default: %u)"), 1));
if (showDebug) if (showDebug)
{ {
strUsage += HelpMessageOpt("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS));
strUsage += HelpMessageOpt("-limitfreerelay=<n>", strprintf("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default: %u)", 15)); strUsage += HelpMessageOpt("-limitfreerelay=<n>", strprintf("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default: %u)", 15));
strUsage += HelpMessageOpt("-relaypriority", strprintf("Require high priority for relaying free or low-fee transactions (default: %u)", 1)); strUsage += HelpMessageOpt("-relaypriority", strprintf("Require high priority for relaying free or low-fee transactions (default: %u)", 1));
strUsage += HelpMessageOpt("-maxsigcachesize=<n>", strprintf("Limit size of signature cache to <n> entries (default: %u)", 50000)); strUsage += HelpMessageOpt("-maxsigcachesize=<n>", strprintf("Limit size of signature cache to <n> entries (default: %u)", 50000));
@ -726,6 +727,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// Set this early so that parameter interactions go to console // Set this early so that parameter interactions go to console
fPrintToConsole = GetBoolArg("-printtoconsole", false); fPrintToConsole = GetBoolArg("-printtoconsole", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true); fLogTimestamps = GetBoolArg("-logtimestamps", true);
fLogTimeMicros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
fLogIPs = GetBoolArg("-logips", false); fLogIPs = GetBoolArg("-logips", false);
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

11
src/util.cpp

@ -108,6 +108,7 @@ bool fDaemon = false;
bool fServer = false; bool fServer = false;
string strMiscWarning; string strMiscWarning;
bool fLogTimestamps = false; bool fLogTimestamps = false;
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
bool fLogIPs = false; bool fLogIPs = false;
volatile bool fReopenDebugLog = false; volatile bool fReopenDebugLog = false;
CTranslationInterface translationInterface; CTranslationInterface translationInterface;
@ -263,9 +264,13 @@ static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine
if (!fLogTimestamps) if (!fLogTimestamps)
return str; return str;
if (*fStartedNewLine) if (*fStartedNewLine) {
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()) + ' ' + str; int64_t nTimeMicros = GetLogTimeMicros();
else strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000);
if (fLogTimeMicros)
strStamped += strprintf(".%06d", nTimeMicros%1000000);
strStamped += ' ' + str;
} else
strStamped = str; strStamped = str;
if (!str.empty() && str[str.size()-1] == '\n') if (!str.empty() && str[str.size()-1] == '\n')

3
src/util.h

@ -28,6 +28,8 @@
#include <boost/signals2/signal.hpp> #include <boost/signals2/signal.hpp>
#include <boost/thread/exceptions.hpp> #include <boost/thread/exceptions.hpp>
static const bool DEFAULT_LOGTIMEMICROS = false;
/** Signals for translation. */ /** Signals for translation. */
class CTranslationInterface class CTranslationInterface
{ {
@ -44,6 +46,7 @@ extern bool fPrintToDebugLog;
extern bool fServer; extern bool fServer;
extern std::string strMiscWarning; extern std::string strMiscWarning;
extern bool fLogTimestamps; extern bool fLogTimestamps;
extern bool fLogTimeMicros;
extern bool fLogIPs; extern bool fLogIPs;
extern volatile bool fReopenDebugLog; extern volatile bool fReopenDebugLog;
extern CTranslationInterface translationInterface; extern CTranslationInterface translationInterface;

8
src/utiltime.cpp

@ -40,6 +40,14 @@ int64_t GetTimeMicros()
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds(); boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
} }
/** Return a time useful for the debug log */
int64_t GetLogTimeMicros()
{
if (nMockTime) return nMockTime*1000000;
return GetTimeMicros();
}
void MilliSleep(int64_t n) void MilliSleep(int64_t n)
{ {

1
src/utiltime.h

@ -12,6 +12,7 @@
int64_t GetTime(); int64_t GetTime();
int64_t GetTimeMillis(); int64_t GetTimeMillis();
int64_t GetTimeMicros(); int64_t GetTimeMicros();
int64_t GetLogTimeMicros();
void SetMockTime(int64_t nMockTimeIn); void SetMockTime(int64_t nMockTimeIn);
void MilliSleep(int64_t n); void MilliSleep(int64_t n);

Loading…
Cancel
Save