Boost logo

Boost :

Subject: Re: [boost] Boost log issues and workarounds
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2019-01-20 09:15:21

On 1/20/19 10:36 AM, hh h via Boost wrote:
> Would you please clarify following questions:
> (1) Will it be a problem to keep the
> BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity",
> ::LibraryGlobalServerityLevel_t) and
> boost::log::sources::severity_logger_mt<::LibraryGlobalServerityLevel_t>)
> in a header file Log.hpp where many sources include the header file
> Log.hpp?

No, it shouldn't be a problem.

> (2) I think that the boost log initialization should be called once
> even in multi threading program to share the same log, is it correct?

Yes. Logging initialization should be performed once, early when the
application starts.

> (3) What are different between add_global_attribute and
> add_thread_attribute? I thought since I use GLOBAL_LOGGER, I should
> use the add_global_attribute, why it got Segmentation fault?

These are different kinds of attributes.

What kind of logger you are using is irrelevant to the kind of
attributes you use.

I can't tell the cause of the crash without a backtrace and a source code.

> (4) What could I be missing that the log file is empty? I am writing
> the log file currently to the /tmp which won't cause any permission
> issues. I tried both static calling boost::log::add_file_log(..) and
> shared pointer boost::shared_ptr<FileSink_t> sink(new FileSink_t(...)
> in the log initial function, it did not make any difference, none of
> it works.

Since you said that flushing makes the log records appear in the file,
this is probably due to buffering in the file stream. I'm assuming
you're not using async logging, otherise it could also be buffering in
the sink frontend.

To avoid buffering in the file stream you can enable auto flush in the
sink backend. This will reduce performance, though.

> (5) Currently I built it using dynamic link, can it use static link?
> What will be the build macro for static link?

You can only use static linking if you use Boost.Log from a single
module of your application.

Boost list run by bdawes at, gregod at, cpdaniel at, john at