From 6c5f69a0e6e62fc220f3b4198dad1f202552e2ad Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Mon, 2 Jun 2008 20:52:40 +0000 Subject: Added --syslog-name, --syslog-facility options. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@662558 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/log/Logger.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'cpp/src/qpid/log/Logger.cpp') diff --git a/cpp/src/qpid/log/Logger.cpp b/cpp/src/qpid/log/Logger.cpp index f2f86e62fc..84096f7e58 100644 --- a/cpp/src/qpid/log/Logger.cpp +++ b/cpp/src/qpid/log/Logger.cpp @@ -63,8 +63,8 @@ struct OstreamOutput : public Logger::Output { }; struct SyslogOutput : public Logger::Output { - SyslogOutput(const std::string& name, int facility_=LOG_USER) - : progName(name), facility(facility_) + SyslogOutput(const Options& opts) + : name(opts.syslogName), facility(opts.syslogFacility.value) { ::openlog(name.c_str(), LOG_PID, facility); } @@ -78,7 +78,7 @@ struct SyslogOutput : public Logger::Output { syslog(LevelTraits::priority(s.level), "%s", m.c_str()); } - std::string progName; + std::string name; int facility; }; @@ -90,9 +90,9 @@ Logger::Logger() : flags(0) { // 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; + Options opts(""); opts.parse(0, 0); - configure(opts,""); + configure(opts); } Logger::~Logger() {} @@ -161,17 +161,17 @@ void Logger::output(std::ostream& out) { output(make_auto_ptr(new OstreamOutput(out))); } -void Logger::syslog(const std::string& progName) { - output(make_auto_ptr(new SyslogOutput(progName))); +void Logger::syslog(const Options& opts) { + output(make_auto_ptr(new SyslogOutput(opts))); } -void Logger::output(const std::string& name) { +void Logger::output(const std::string& name, const Options& opts) { if (name=="stderr") output(clog); else if (name=="stdout") output(cout); else if (name=="syslog") - syslog(syslogName); + syslog(opts); else output(make_auto_ptr(new OstreamOutput(name))); } @@ -209,21 +209,16 @@ void Logger::add(Statement& s) { statements.insert(&s); } -void Logger::configure(const Options& opts, const std::string& prog) -{ +void Logger::configure(const Options& opts) { clear(); Options o(opts); if (o.trace) o.selectors.push_back("trace+"); - { - ScopedLock l(lock); - syslogName=prog; - } format(o); select(Selector(o)); - void (Logger::* outputFn)(const std::string&) = &Logger::output; + void (Logger::* outputFn)(const std::string&, const Options&) = &Logger::output; for_each(o.outputs.begin(), o.outputs.end(), - boost::bind(outputFn, this, _1)); + boost::bind(outputFn, this, _1, boost::cref(o))); } }} // namespace qpid::log -- cgit v1.2.1