diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/log/Logger.cpp | 11 | ||||
-rw-r--r-- | cpp/src/qpid/log/Options.cpp | 4 | ||||
-rw-r--r-- | cpp/src/qpid/sys/posix/Time.cpp | 7 | ||||
-rw-r--r-- | cpp/src/qpid/sys/windows/Time.cpp | 9 |
4 files changed, 28 insertions, 3 deletions
diff --git a/cpp/src/qpid/log/Logger.cpp b/cpp/src/qpid/log/Logger.cpp index 2339a62114..1600822142 100644 --- a/cpp/src/qpid/log/Logger.cpp +++ b/cpp/src/qpid/log/Logger.cpp @@ -79,8 +79,12 @@ void Logger::log(const Statement& s, const std::string& msg) { std::ostringstream os; if (!prefix.empty()) os << prefix << ": "; - if (flags&TIME) - qpid::sys::outputFormattedNow(os); + if (flags&TIME) { + if (flags&HIRES) + qpid::sys::outputHiresNow(os); + else + qpid::sys::outputFormattedNow(os); + } if (flags&LEVEL) os << LevelTraits::name(s.level) << " "; if (flags&THREAD) @@ -129,7 +133,8 @@ int Logger::format(const Options& opts) { bitIf(opts.time, TIME) | bitIf(opts.source, (FILE|LINE)) | bitIf(opts.function, FUNCTION) | - bitIf(opts.thread, THREAD); + bitIf(opts.thread, THREAD) | + bitIf(opts.hiresTs, HIRES); format(flags); return flags; } diff --git a/cpp/src/qpid/log/Options.cpp b/cpp/src/qpid/log/Options.cpp index 24ef413cbc..0001d00bdf 100644 --- a/cpp/src/qpid/log/Options.cpp +++ b/cpp/src/qpid/log/Options.cpp @@ -38,6 +38,7 @@ Options::Options(const std::string& argv0_, const std::string& name_) : thread(false), source(false), function(false), + hiresTs(false), trace(false), sinkOptions (SinkOptions::create(argv0_)) { @@ -65,6 +66,7 @@ Options::Options(const std::string& argv0_, const std::string& name_) : ("log-source", optValue(source,"yes|no"), "Include source file:line in log messages") ("log-thread", optValue(thread,"yes|no"), "Include thread ID in log messages") ("log-function", optValue(function,"yes|no"), "Include function signature in log messages") + ("log-hires-timestamp", optValue(hiresTs,"yes|no"), "Use unformatted hi-res timestamp in log messages") ("log-prefix", optValue(prefix,"STRING"), "Prefix to append to all log messages") ; add(*sinkOptions); @@ -80,6 +82,7 @@ Options::Options(const Options &o) : thread(o.thread), source(o.source), function(o.function), + hiresTs(o.hiresTs), trace(o.trace), prefix(o.prefix), sinkOptions (SinkOptions::create(o.argv0)) @@ -97,6 +100,7 @@ Options& Options::operator=(const Options& x) { thread = x.thread; source = x.source; function = x.function; + hiresTs = x.hiresTs; trace = x.trace; prefix = x.prefix; *sinkOptions = *x.sinkOptions; diff --git a/cpp/src/qpid/sys/posix/Time.cpp b/cpp/src/qpid/sys/posix/Time.cpp index b3858279b4..9661f0c5e8 100644 --- a/cpp/src/qpid/sys/posix/Time.cpp +++ b/cpp/src/qpid/sys/posix/Time.cpp @@ -27,6 +27,7 @@ #include <stdio.h> #include <sys/time.h> #include <unistd.h> +#include <iomanip> namespace { int64_t max_abstime() { return std::numeric_limits<int64_t>::max(); } @@ -103,6 +104,12 @@ void outputFormattedNow(std::ostream& o) { o << " "; } +void outputHiresNow(std::ostream& o) { + ::timespec time; + ::clock_gettime(CLOCK_REALTIME, &time); + o << time.tv_sec << "." << std::setw(9) << std::setfill('0') << time.tv_nsec << "s "; +} + void sleep(int secs) { ::sleep(secs); } diff --git a/cpp/src/qpid/sys/windows/Time.cpp b/cpp/src/qpid/sys/windows/Time.cpp index 16d09fcdc0..56eade651a 100644 --- a/cpp/src/qpid/sys/windows/Time.cpp +++ b/cpp/src/qpid/sys/windows/Time.cpp @@ -97,4 +97,13 @@ void outputFormattedNow(std::ostream& o) { &timeinfo); o << time_string << " "; } + +void outputHiresNow(std::ostream& o) { +// TODO: This is a stub - replace with windows code that will do the equivalent +// of the Linux code commented out below. (kpvdr) +// ::timespec time; +// ::clock_gettime(CLOCK_REALTIME, &time); +// o << time.tv_sec << "." << std::setw(9) << std::setfill('0') << time.tv_nsec << "s "; + o << "XXXXXXXXX.XXXXXXXXXs "; +} }} |