Skip to content
Snippets Groups Projects
Commit 8032345c authored by andreas's avatar andreas
Browse files

readded redirection of logging to file

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2589 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 0c28346f
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,16 @@ void pop_verb()
Logger::Instance().PopVerbosityLevel();
}
void pop_verb_file()
{
Logger::Instance().PopFile();
}
void push_verb_file(const String& filename)
{
Logger::Instance().PushFile(filename);
}
void log_error(const String& m) {LOGN_ERROR(m);}
void log_message(const String& m) {LOGN_MESSAGE(m);}
void log_verbose(const String& m) {LOGN_VERBOSE(m);}
......@@ -51,6 +61,8 @@ void export_Logger()
def("PushVerbosityLevel",push_verb);
def("PopVerbosityLevel",pop_verb);
def("PushVerbosityFile",push_verb_file);
def("PopVerbosityFile",pop_verb_file);
def("LogError",log_error);
def("LogMessage",log_message);
......
......@@ -17,6 +17,7 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <ost/log.hh>
......@@ -45,15 +46,24 @@ Logger& Logger::Instance()
Logger::Logger():
level_(0),
level_stack_(),
null_(new DevNull())
null_(new DevNull()),
stream_(0),
ostream_stack_()
{
ostream_stack_.push(new std::ostream(std::cerr.rdbuf()));
stream_.rdbuf(ostream_stack_.top()->rdbuf());
}
Logger::Logger(const Logger&):
level_(0),
level_stack_(),
null_(0)
{}
null_(0),
stream_(0),
ostream_stack_()
{
ostream_stack_.push(new std::ostream(std::cerr.rdbuf()));
stream_.rdbuf(ostream_stack_.top()->rdbuf());
}
Logger& Logger::operator=(const Logger&)
{
......@@ -81,11 +91,25 @@ void Logger::PopVerbosityLevel()
std::ostream& Logger::operator()(enum LogLevel l)
{
if(l<=level_) {
return std::cerr;
return stream_;
}
return null_;
}
void Logger::PushFile(const String& fn)
{
ostream_stack_.push(new std::ofstream(fn.c_str()));
stream_.rdbuf(ostream_stack_.top()->rdbuf());
}
void Logger::PopFile()
{
if(ostream_stack_.size()>1) {
delete ostream_stack_.top();
ostream_stack_.pop();
stream_.rdbuf(ostream_stack_.top()->rdbuf());
}
}
} // ns
......
......@@ -26,6 +26,8 @@
namespace ost {
typedef std::stack<std::ostream*> OStreamStack;
// singleton
class DLLEXPORT_OST_BASE Logger {
public:
......@@ -40,6 +42,8 @@ public:
void PushVerbosityLevel(int level);
void PopVerbosityLevel();
void PushFile(const String& filename);
void PopFile();
std::ostream& operator()(enum LogLevel);
......@@ -51,11 +55,13 @@ protected:
Logger();
Logger(const Logger&);
Logger& operator=(const Logger&);
private:
int level_;
std::stack<int> level_stack_;
std::ostream null_;
std::ostream stream_;
OStreamStack ostream_stack_;
};
#define PUSH_VERBOSITY(n) ::ost::Logger::Instance().PushVerbosityLevel(n)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment