Boost logo

Boost :

Subject: Re: [boost] [logging] Interest check on logging library.
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2008-12-27 21:02:51


On Sat, Dec 27, 2008 at 12:18 PM, Jason Wagner <jason_at_[hidden]> wrote:
>> -------Original Message-------
> I'm differentiating macros from simple defines.
>
> #define LOG_LINE filename(__FILE__) << line(__LINE__) << function(__FUNCTION__)
>
> will be in the library in some form in the future.

That would work when the user explicitly wants to log __FILE__ or
__LINE__ but I meant that it's desirable to log them implicitly,
automatically. To make this work, you need the logging itself to use
macros, which I think is quite fine.

>> if( logging::warnings )
>> log << "Warning";
>>
>> where log simply implements std::ostream.
>>
>> You could put the if in a macro but frankly, I personally don't mind
>> typing it every time; compared to the rest of the junk I have to type
>> to format a meaningful logging message, the if is not an issue. As a
>> bonus, you don't have to worry about functions referenced by a logging
>> expression being executed when logging is not enabled.
>
> I'm not a fan of the macros, either. What's really the difference between what you wrote and:
>
> LOG_DEBUG(log) << "Warning";
>
> other than the latter being ugly.

I don't find LOG_DEBUG(log)<<"Warning" ugly at all, my point was that
the reason you'd use something like LOG_DEBUG(log)<<"foo" or
log<<severity::info()<<"foo" is so that the logging expression could
compile to nothing depending on how the logging is configured.

My point was that I think it's better to leave it up to the user to
deal with the condition "manually", as in

if( logging::warnings )
  log << "Warning";

or

if( logging::warnings && logging::severity>10 )
  log << "Severe warning";

or even

if( logging::warnings )
{
  log << "Warning";
  if( logging::severity>10 )
    log << "Severe warning";
}

That way the logging library only needs to expose two independent
interfaces, one that provides the "log" object (which is just a
std::ostream &) and another that provides convenient compile-time or
run-time flags for users to type in if statements as above.

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


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