Boost logo

Boost :

From: Maxim Yegorushkin (e-maxim_at_[hidden])
Date: 2004-10-29 01:52:33


On Thu, 28 Oct 2004 19:29:18 +0200, John Torjo <john.lists_at_[hidden]> wrote:

> As for scoped logs, to make a long story short, you'll be able to do:
> logger gui("app.gui")
> if (gui) gui.stream() << "something GUIsh";
> // or (equivalent)
> BOOOST_SCOPEDLOG(gui) << "something GUIsh";

There is an option for avoiding if() checks in client code at all. All you have to do is to implement operator<< for logger class.

    class logger
    {
        // ...
        template<class T>
        logger const& operator<<(T const& t) const
        {
            if(/*the check is here*/)
                this->stream_ << t;
            return *this;
        }
        // ...
    };

And then in client code:

    logger("app.gui") << "something GUIsh";

Though I am not sure, if a compiler will be able to optimize checks for every operator<<() to a single check for the entire output expression.

-- 
Maxim Yegorushkin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk