diff options
author | Stephen D. Huston <shuston@apache.org> | 2011-10-21 14:42:12 +0000 |
---|---|---|
committer | Stephen D. Huston <shuston@apache.org> | 2011-10-21 14:42:12 +0000 |
commit | f83677056891e436bf5ba99e79240df2a44528cd (patch) | |
tree | 625bfd644b948e89105630759cf6decb0435354d /cpp/src/qpid/log | |
parent | ebfd9ff053b04ab379acfc0fefedee5a31b6d8a5 (diff) | |
download | qpid-python-QPID-2519.tar.gz |
Merged out from trunkQPID-2519
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/QPID-2519@1187375 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/log')
-rw-r--r-- | cpp/src/qpid/log/Logger.cpp | 21 | ||||
-rw-r--r-- | cpp/src/qpid/log/Options.cpp | 4 | ||||
-rw-r--r-- | cpp/src/qpid/log/Statement.cpp | 5 | ||||
-rw-r--r-- | cpp/src/qpid/log/posix/SinkOptions.cpp | 2 | ||||
-rw-r--r-- | cpp/src/qpid/log/windows/SinkOptions.cpp | 4 | ||||
-rw-r--r-- | cpp/src/qpid/log/windows/SinkOptions.h | 2 |
6 files changed, 25 insertions, 13 deletions
diff --git a/cpp/src/qpid/log/Logger.cpp b/cpp/src/qpid/log/Logger.cpp index 2217cdddbd..1600822142 100644 --- a/cpp/src/qpid/log/Logger.cpp +++ b/cpp/src/qpid/log/Logger.cpp @@ -22,6 +22,7 @@ #include "qpid/memory.h" #include "qpid/sys/Thread.h" #include "qpid/sys/Time.h" +#include "qpid/DisableExceptionLogging.h" #include <boost/pool/detail/singleton.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> @@ -48,11 +49,16 @@ Logger& Logger::instance() { } Logger::Logger() : flags(0) { + // Disable automatic logging in Exception constructors to avoid + // re-entrant use of logger singleton if there is an error in + // option parsing. + DisableExceptionLogging del; + // Initialize myself from env variables so all programs // (e.g. tests) can use logging even if they don't parse // command line args. Options opts(""); - opts.parse(0, 0); + opts.parse(0, 0); configure(opts); } @@ -73,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) @@ -123,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; } @@ -140,7 +151,7 @@ void Logger::configure(const Options& opts) { Options o(opts); if (o.trace) o.selectors.push_back("trace+"); - format(o); + format(o); select(Selector(o)); setPrefix(opts.prefix); options.sinkOptions->setup(this); 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/log/Statement.cpp b/cpp/src/qpid/log/Statement.cpp index 6a32b50096..7dfdf08703 100644 --- a/cpp/src/qpid/log/Statement.cpp +++ b/cpp/src/qpid/log/Statement.cpp @@ -27,8 +27,6 @@ namespace qpid { namespace log { namespace { -using namespace std; - struct NonPrint { bool operator()(unsigned char c) { return !isprint(c) && !isspace(c); } }; const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; @@ -39,7 +37,7 @@ std::string quote(const std::string& str) { if (n==0) return str; std::string ret; ret.reserve(str.size()+2*n); // Avoid extra allocations. - for (string::const_iterator i = str.begin(); i != str.end(); ++i) { + for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) { if (nonPrint(*i)) { ret.push_back('\\'); ret.push_back('x'); @@ -50,7 +48,6 @@ std::string quote(const std::string& str) { } return ret; } - } void Statement::log(const std::string& message) { diff --git a/cpp/src/qpid/log/posix/SinkOptions.cpp b/cpp/src/qpid/log/posix/SinkOptions.cpp index 292e9147f6..ffa7633e3b 100644 --- a/cpp/src/qpid/log/posix/SinkOptions.cpp +++ b/cpp/src/qpid/log/posix/SinkOptions.cpp @@ -180,7 +180,7 @@ qpid::log::SinkOptions& SinkOptions::operator=(const qpid::log::SinkOptions& rhs } void SinkOptions::detached(void) { - if (logToStderr && !logToStdout && !logToSyslog) { + if (logToStderr && !logToStdout && !logToSyslog && logFile.empty()) { logToStderr = false; logToSyslog = true; } diff --git a/cpp/src/qpid/log/windows/SinkOptions.cpp b/cpp/src/qpid/log/windows/SinkOptions.cpp index 28f4b267e0..0c74bea64e 100644 --- a/cpp/src/qpid/log/windows/SinkOptions.cpp +++ b/cpp/src/qpid/log/windows/SinkOptions.cpp @@ -53,7 +53,7 @@ static int eventTypes[qpid::log::LevelTraits::COUNT] = { class EventLogOutput : public qpid::log::Logger::Output { public: - EventLogOutput(const std::string& sourceName) : logHandle(0) + EventLogOutput(const std::string& /*sourceName*/) : logHandle(0) { logHandle = OpenEventLog(0, "Application"); } @@ -83,7 +83,7 @@ private: HANDLE logHandle; }; -SinkOptions::SinkOptions(const std::string& argv0) +SinkOptions::SinkOptions(const std::string& /*argv0*/) : qpid::log::SinkOptions(), logToStderr(true), logToStdout(false), diff --git a/cpp/src/qpid/log/windows/SinkOptions.h b/cpp/src/qpid/log/windows/SinkOptions.h index 605822fd46..f270c504a2 100644 --- a/cpp/src/qpid/log/windows/SinkOptions.h +++ b/cpp/src/qpid/log/windows/SinkOptions.h @@ -26,7 +26,7 @@ namespace qpid { namespace log { namespace windows { -struct SinkOptions : public qpid::log::SinkOptions { +struct QPID_COMMON_CLASS_EXTERN SinkOptions : public qpid::log::SinkOptions { QPID_COMMON_EXTERN SinkOptions(const std::string& argv0); virtual ~SinkOptions() {} |