Boost logo

Boost Users :

Subject: Re: [Boost-users] Include line number in boost logs
From: Leon Mlakar (leon_at_[hidden])
Date: 2015-08-25 09:42:02


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.

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.

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

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