summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/log/Logger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/log/Logger.cpp')
-rw-r--r--cpp/src/qpid/log/Logger.cpp67
1 files changed, 3 insertions, 64 deletions
diff --git a/cpp/src/qpid/log/Logger.cpp b/cpp/src/qpid/log/Logger.cpp
index b4f5bde186..07e4245399 100644
--- a/cpp/src/qpid/log/Logger.cpp
+++ b/cpp/src/qpid/log/Logger.cpp
@@ -17,18 +17,17 @@
*/
#include "Logger.h"
+#include "Options.h"
+#include "SinkOptions.h"
#include "qpid/memory.h"
#include "qpid/sys/Thread.h"
#include <boost/pool/detail/singleton.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
-#include <boost/scoped_ptr.hpp>
#include <algorithm>
#include <sstream>
-#include <fstream>
#include <iomanip>
#include <stdexcept>
-#include <syslog.h>
#include <time.h>
@@ -43,45 +42,6 @@ inline void Logger::enable_unlocked(Statement* s) {
s->enabled=selector.isEnabled(s->level, s->function);
}
-struct OstreamOutput : public Logger::Output {
- OstreamOutput(std::ostream& o) : out(&o) {}
-
- OstreamOutput(const string& file)
- : out(new ofstream(file.c_str(), ios_base::out | ios_base::app)),
- mine(out)
- {
- if (!out->good())
- throw std::runtime_error("Can't open log file: "+file);
- }
-
- void log(const Statement&, const std::string& m) {
- *out << m << flush;
- }
-
- ostream* out;
- boost::scoped_ptr<ostream> mine;
-};
-
-struct SyslogOutput : public Logger::Output {
- SyslogOutput(const Options& opts)
- : name(opts.syslogName), facility(opts.syslogFacility.value)
- {
- ::openlog(name.c_str(), LOG_PID, facility);
- }
-
- ~SyslogOutput() {
- ::closelog();
- }
-
- void log(const Statement& s, const std::string& m)
- {
- syslog(LevelTraits::priority(s.level), "%s", m.c_str());
- }
-
- std::string name;
- int facility;
-};
-
Logger& Logger::instance() {
return boost::details::pool::singleton_default<Logger>::instance();
}
@@ -158,25 +118,6 @@ void Logger::output(std::auto_ptr<Output> out) {
outputs.push_back(out.release());
}
-void Logger::output(std::ostream& out) {
- output(make_auto_ptr<Output>(new OstreamOutput(out)));
-}
-
-void Logger::syslog(const Options& opts) {
- output(make_auto_ptr<Output>(new SyslogOutput(opts)));
-}
-
-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(opts);
- else
- output(make_auto_ptr<Output>(new OstreamOutput(name)));
-}
-
void Logger::clear() {
select(Selector()); // locked
format(0); // locked
@@ -218,10 +159,8 @@ void Logger::configure(const Options& opts) {
o.selectors.push_back("trace+");
format(o);
select(Selector(o));
- 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);
+ options.sinkOptions->setup(this);
}
void Logger::setPrefix(const std::string& p) { prefix = p; }