I wanted to share a simple debugging technique that I use with tntnet.
To debug the output that I send to the client using reply.out() stream,
I use the class below that sends the output to the client and
redirects a copy of the output to the tntnet log:
-----------------------------------------------------
#include <iostream>
#include <sstream>
class tee {
std::ostream& m_real;
std::ostream& m_copy;
public:
tee(std::ostream& real, std::ostream& copy) throw()
: m_real(real)
, m_copy(copy)
{ }
template<typename T>
tee& operator<<(const T& data)
{ m_real << data; m_copy << data; return *this; }
};
-----------------------------------------------------
I define OUT macro shown below
#define OUT tee(reply.out(), std::cerr)
and use it in my .ecpp files instead of reply.out():
OUT << "some output";
To stop debugging, I re-define the macro:
#define OUT reply.out()
In order to clearly separate my debugging output from the rest of the
log I use bufTee class instead of tee class:
-----------------------------------------------------
#include <iterator>
#include "tee.h"
class bufTee {
std::stringstream m_buf;
std::ostream& m_copy;
tee m_tee;
public:
bufTee(std::ostream& real, std::ostream& copy) throw()
: m_copy(copy)
, m_tee(real, m_buf)
{ }
~bufTee() {
m_copy << std::endl;
std::copy(std::istream_iterator<char>(m_buf),
std::istream_iterator<char>(),
std::ostream_iterator<char>(m_copy));
m_copy << std::endl << std::endl;
}
template<typename T>
bufTee& operator<<(const T& data)
{ m_tee << data; return *this; }
};
-----------------------------------------------------
If you have your own debugging tips it would be helpful if you could
share them with this list.
I'm also interested if there is a way to duplicate what is being send to
ostream without wrapping it with something like tee or bufTee.
Best regards,
Yuri
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general