#ifndef H_CORAL_LIB_DEBUGSTREAM
#define H_CORAL_LIB_DEBUGSTREAM
// This file is part of the Coral project.
// Please read the copyright notice in the LICENSE file.

#include <ostream>
#include <iostream>
#include <streambuf>
#include <sstream>
#include <coral/coral.h>

#include <coral/lib/python_support.h>

NAMESPACE_BEGIN(coral);

#ifndef SWIG
enum debuglevel {
     DEBUGLEVEL_ALL,
     DEBUGLEVEL_DEBUG,
     DEBUGLEVEL_INFO,
     DEBUGLEVEL_WARNING,
     DEBUGLEVEL_ERROR,
     DEBUGLEVEL_CRITICAL,
     DEBUGLEVEL_NONE,
};
#endif

#ifndef SWIG

extern EXPORT_coral const char* debuglevel_str[];

/*
 * Debug streambuf which outputs to given output stream as well
 * as to an internal stringstream buffer
 *
 */
class EXPORT_coral debugstreambuf
: public std::basic_streambuf<char, std::char_traits<char> > {
private:
     std::ostringstream m_output1;
     std::ostream& m_output2;
     debuglevel current_message_dlevel;
public:
     debugstreambuf(std::ostream& out);
     ~debugstreambuf();
     debuglevel& curMessageLevel() { return current_message_dlevel; }
     std::streamsize xsputn(const char* s, std::streamsize n);
     int overflow(int c = traits_type::eof());
     std::ostringstream& get_string_stream();
};

/*
 * The log output stream, which writes to std::clog and the dlogbuf
 */
extern EXPORT_coral std::ostream dlog;

extern EXPORT_coral std::ostream& operator<<(std::ostream& out, debuglevel d);

#endif


#ifndef SWIG
/*
 * Sets debuglevel, returns old.
 */
debuglevel setDebugLevel(debuglevel d);
/*
 * Returns debuglevel
 */
debuglevel getDebugLevel();
#endif

std::string getDebugLog();

void setDebugObserver(PyObject*);

NAMESPACE_END();

#endif
