Creating a debug stream

Discussion in 'C++' started by ciccio, Sep 11, 2008.

  1. ciccio

    ciccio Guest

    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?

    --
    "Yes, it's the right planet, all right, " he said again.
    "Right planet, wrong universe. "
     
    ciccio, Sep 11, 2008
    #1
    1. Advertising

  2. ciccio

    Zeppe Guest

    Dear ciccio,

    ciccio wrote:
    > 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
     
    Zeppe, Sep 11, 2008
    #2
    1. Advertising

  3. ciccio

    James Kanze Guest

    On Sep 11, 7:01 pm, ciccio <> wrote:
    > 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.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 11, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmusson, Lars
    Replies:
    1
    Views:
    782
    popov
    Apr 30, 2004
  2. Replies:
    9
    Views:
    670
    Alex Buell
    Apr 27, 2006
  3. Alexander Korsunsky

    get stream mode flags from an opened stream

    Alexander Korsunsky, Feb 17, 2007, in forum: C++
    Replies:
    1
    Views:
    476
    John Harrison
    Feb 17, 2007
  4. dolphin
    Replies:
    6
    Views:
    595
    Thomas Fritsch
    Mar 18, 2007
  5. mrstephengross
    Replies:
    3
    Views:
    418
    James Kanze
    May 10, 2007
Loading...

Share This Page