Skip to content
Snippets Groups Projects
Commit 766db39f authored by Andreas Schenk's avatar Andreas Schenk
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 bcecdc60
No related branches found
No related tags found
No related merge requests found
......@@ -156,6 +156,12 @@ void export_Logger()
.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("PopVerbosityLevel",pop_verb);
def("GetVerbosityLevel",get_verb);
......
......@@ -20,6 +20,7 @@
#define OST_LOG_SINK_HH
#include <ostream>
#include <sstream>
#include <iostream>
#include <fstream>
#include <stack>
......@@ -51,6 +52,23 @@ private:
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 {
public:
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