Boost logo

Boost Users :

Subject: Re: [Boost-users] How to wrap boost::log class to user?
From: Leon Mlakar (leon_at_[hidden])
Date: 2016-11-14 07:05:09


On 14.11.2016 12:21, Bruce wrote:
> Hi,
> I am coding a project and I use boost::log.
> I need to supply the log function to user, but I don't want the user
> use boost::log directly.
> I want to wrap the boost::log into my class. But I still want to keep
> the << cascade feature.
>
> Basically, I need to implement a MyLogger class, which support:
>
> MyLogger(info) << bla bla bla;
> MyLogger(trace) << bla bla bla;

I'm not sure this is the best way to use Boost.Log. There are at least
two reasons why logging macros might be a better idea:
  1. Using own operators you cannot implicitly enforce __LINE__,
__FILE__ and other compiler generated macros to supplement logged
information
  2. Boost.Log will not create log record if no sink will accept it. By
using logging macros it is easy to ensure that logged information (bla
bla bla) is not evaluated if it's not going to be recorded; using own
operator overload the logging information will always be evaluated. And
in my experience logging information will quickly enough get non-trivial
and expensive to calculate. So in consequence logging will slow down you
code even in production use with logging thresholds raised to log errors
and warnings only.

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