Skip to content
Snippets Groups Projects
Commit 3247e572 authored by Andreas Schenk's avatar Andreas Schenk Committed by Valerio Mariani
Browse files

added StringLogSink

StringLogSink is very similar to the StreamLogSink, but the encapsulation of the
ostringstream in the Sink allows much easier export to Python
parent 9c6f29ea
Branches
Tags
No related merge requests found
...@@ -156,6 +156,12 @@ void export_Logger() ...@@ -156,6 +156,12 @@ void export_Logger()
.def("LogMessage", &FileLogSink::LogMessage) .def("LogMessage", &FileLogSink::LogMessage)
; ;
class_<StringLogSink, StringLogSinkPtr, bases<LogSink>,
boost::noncopyable >("StringLogSink", init<>())
.def("LogMessage", &StringLogSink::LogMessage)
.def("GetLog", &StringLogSink::GetLog)
;
def("PushVerbosityLevel",push_verb); def("PushVerbosityLevel",push_verb);
def("PopVerbosityLevel",pop_verb); def("PopVerbosityLevel",pop_verb);
def("GetVerbosityLevel",get_verb); def("GetVerbosityLevel",get_verb);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#define OST_LOG_SINK_HH #define OST_LOG_SINK_HH
#include <ostream> #include <ostream>
#include <sstream>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <stack> #include <stack>
...@@ -51,6 +52,23 @@ private: ...@@ -51,6 +52,23 @@ private:
std::ostream& stream_; std::ostream& stream_;
}; };
class DLLEXPORT StringLogSink : public LogSink {
public:
StringLogSink():LogSink(),stream_(){}
virtual void LogMessage(const String& message, int severity){
stream_ << message;
}
String GetLog() const
{
return stream_.str();
}
private:
std::ostringstream stream_;
};
typedef boost::shared_ptr<StringLogSink> StringLogSinkPtr;
class DLLEXPORT FileLogSink : public LogSink { class DLLEXPORT FileLogSink : public LogSink {
public: public:
FileLogSink(const String& file_name):stream_(file_name.c_str(), std::ios::out){} FileLogSink(const String& file_name):stream_(file_name.c_str(), std::ios::out){}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment