Creating a debug stream

C

ciccio

Hi,

I would like to write debug output to my screen but I don't want to use
std::cout or std::cerr but rather a thing called debug which would write
to std:cerr. Also I would like to have that each new line would start with
a certain starting character.

An example would then be

debug << "Debug line 1\nDebug line 2" << std::endl;

which should result in the following output to stderr

(D) Debug line 1
(D) Debug line 2

Is this possible?
 
Z

Zeppe

Dear ciccio,
Hi,

I would like to write debug output to my screen but I don't want to use
std::cout or std::cerr but rather a thing called debug which would write
to std:cerr. Also I would like to have that each new line would start
with a certain starting character.

You can google "c++ log library". A good one seems to be pantheios
(http://pantheios.sourceforge.net/) but yo may just require something
simpler.

Best wishes,

Zeppe
 
J

James Kanze

I would like to write debug output to my screen but I don't
want to use std::cout or std::cerr but rather a thing called
debug which would write to std:cerr. Also I would like to have
that each new line would start with a certain starting
character.
An example would then be
debug << "Debug line 1\nDebug line 2" << std::endl;
which should result in the following output to stderr
(D) Debug line 1
(D) Debug line 2
Is this possible?

Sure. This is a standard application of a filtering streambuf.
See http://kanze.james.neuf.fr/articles/fltrsbf1.html and
http://kanze.james.neuf.fr/articles/fltrsbf2.html.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top