summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/log
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-07-04 19:07:33 +0000
committerAlan Conway <aconway@apache.org>2008-07-04 19:07:33 +0000
commitd738d179e4c040e62438516bc0992736d00b902f (patch)
tree73694d534d1fd2526dfe64b874f60944ab5a92b7 /cpp/src/qpid/log
parent3a00f4fdffe6de06873e9d4d3569bb7531adda85 (diff)
downloadqpid-python-d738d179e4c040e62438516bc0992736d00b902f.tar.gz
Cluster prototype: handles client-initiated commands (not dequeues)
Details - Cluster.cpp: serializes all frames thru cluster (see below) - broker/ConnectionManager: Added handler chain in front of Connection::received. - sys::Fork and ForkWithMessage - abstractions for forking with posix impl. - tests/ForkedBroker.h: test utility to fork a broker process. - broker/SignalHandler: Encapsulated signal handling from qpidd.cpp - Various minor logging & error message improvements to aid debugging. NB: current impl will not scale. It is functional working starting point so we can start testing & profiling to find the right optimizations. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@674107 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/log')
-rw-r--r--cpp/src/qpid/log/Logger.cpp8
-rw-r--r--cpp/src/qpid/log/Logger.h5
-rw-r--r--cpp/src/qpid/log/Options.cpp1
-rw-r--r--cpp/src/qpid/log/Options.h1
-rw-r--r--cpp/src/qpid/log/Statement.cpp3
5 files changed, 16 insertions, 2 deletions
diff --git a/cpp/src/qpid/log/Logger.cpp b/cpp/src/qpid/log/Logger.cpp
index 30cec2f0f7..ce8a3556a8 100644
--- a/cpp/src/qpid/log/Logger.cpp
+++ b/cpp/src/qpid/log/Logger.cpp
@@ -111,6 +111,8 @@ Logger::Output::~Output() {}
void Logger::log(const Statement& s, const std::string& msg) {
// Format the message outside the lock.
std::ostringstream os;
+ if (!prefix.empty())
+ os << prefix << ": ";
if (flags&TIME)
{
const char * month_abbrevs[] = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" };
@@ -134,7 +136,7 @@ void Logger::log(const Statement& s, const std::string& msg) {
if (flags&LEVEL)
os << LevelTraits::name(s.level) << " ";
if (flags&THREAD)
- os << "[" << qpid::sys::Thread::logId() << "] ";
+ os << "[0x" << hex << qpid::sys::Thread::logId() << "] ";
if (flags&FILE)
os << s.file << ":";
if (flags&LINE)
@@ -145,6 +147,7 @@ void Logger::log(const Statement& s, const std::string& msg) {
os << " ";
os << msg << endl;
std::string formatted=os.str();
+ std::cout << "FORMATTED: " << formatted << std::endl; // FIXME aconway 2008-07-04:
{
ScopedLock l(lock);
@@ -220,6 +223,9 @@ void Logger::configure(const Options& opts) {
void (Logger::* outputFn)(const std::string&, const Options&) = &Logger::output;
for_each(o.outputs.begin(), o.outputs.end(),
boost::bind(outputFn, this, _1, boost::cref(o)));
+ setPrefix(opts.prefix);
}
+void Logger::setPrefix(const std::string& p) { prefix = p; }
+
}} // namespace qpid::log
diff --git a/cpp/src/qpid/log/Logger.h b/cpp/src/qpid/log/Logger.h
index 657c8848a0..fa38678bba 100644
--- a/cpp/src/qpid/log/Logger.h
+++ b/cpp/src/qpid/log/Logger.h
@@ -90,8 +90,12 @@ class Logger : private boost::noncopyable {
/** Add an output destination for messages */
void output(std::auto_ptr<Output> out);
+ /** Set a prefix for all messages */
+ void setPrefix(const std::string& prefix);
+
/** Reset the logger to it's original state. */
void clear();
+
private:
typedef boost::ptr_vector<Output> Outputs;
@@ -104,6 +108,7 @@ class Logger : private boost::noncopyable {
Outputs outputs;
Selector selector;
int flags;
+ std::string prefix;
};
}} // namespace qpid::log
diff --git a/cpp/src/qpid/log/Options.cpp b/cpp/src/qpid/log/Options.cpp
index 0fb7fb4cbb..e28f82648e 100644
--- a/cpp/src/qpid/log/Options.cpp
+++ b/cpp/src/qpid/log/Options.cpp
@@ -142,6 +142,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-prefix", optValue(prefix,"STRING"), "Prefix to append to all log messages")
("syslog-name", optValue(syslogName, "NAME"), "Name to use in syslog messages")
("syslog-facility", optValue(syslogFacility,"LOG_XXX"), "Facility to use in syslog messages")
;
diff --git a/cpp/src/qpid/log/Options.h b/cpp/src/qpid/log/Options.h
index 25db7f3474..13fca38f9d 100644
--- a/cpp/src/qpid/log/Options.h
+++ b/cpp/src/qpid/log/Options.h
@@ -45,6 +45,7 @@ struct Options : public qpid::Options {
bool trace;
std::string syslogName;
SyslogFacility syslogFacility;
+ std::string prefix;
};
diff --git a/cpp/src/qpid/log/Statement.cpp b/cpp/src/qpid/log/Statement.cpp
index db5d92c50a..c2b286f1e7 100644
--- a/cpp/src/qpid/log/Statement.cpp
+++ b/cpp/src/qpid/log/Statement.cpp
@@ -30,7 +30,7 @@ namespace log {
namespace {
using namespace std;
-struct NonPrint { bool operator()(unsigned char c) { return !isprint(c); } };
+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' };
@@ -43,6 +43,7 @@ std::string quote(const std::string& str) {
for (string::const_iterator i = str.begin(); i != str.end(); ++i) {
if (nonPrint(*i)) {
ret.push_back('\\');
+ ret.push_back('x');
ret.push_back(hex[((*i) >> 4)&0xf]);
ret.push_back(hex[(*i) & 0xf]);
}