Boost logo

Boost Users :

Subject: Re: [Boost-users] Include line number in boost logs
From: Florian Lindner (mailinglists_at_[hidden])
Date: 2015-08-26 03:51:55


Leon Mlakar wrote:

> On 25.08.2015 11:15, Florian Lindner wrote:
>> I finally got it. Shared the answer on stack overflow:
>>
>> http://stackoverflow.com/a/32200033/3585934
>>
>>
>>
> Thank you for sharing this. I'd just recommend to write macro #define's
> in such a way that they are syntactically and semantically neutral ...
> using do { .... macro contents ... } while (false) is a good way to
> achieve this. For instance, this:
>
> #define logInfo(methodname, message) do { \
> LOG_LOCATION; \
> BOOST_LOG_SEV(_log, boost::log::trivial::severity_level::trace) <<
> message \
> while (false)
>
> would allow constructs such as:
>
> if (something)
> logInfo("my_func", "my message");
>
> which not only would not fail with compilation errors but would behave
> really strange with your original code.

Ah, thanks, that sounds wise. Isn't is sufficient to just use curly braces
{...} instead of do{..} while (false)?

> I never used any of my accounts on stackoverflow and can't write a
> comment there, hence I'm (ab)using an opportunity to comment here.

I will update my anwser there.

> Just a footnote: isn't methodname rather redundant since you already
> have __func__ in the LOG_LOCATION?

Haha, you're right. I'm designed the macros as a drop in replacement and
using the same API. That's why the methodname is there.

Best Regards,
Florian

>
> Cheers,
>
> Leon


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net