Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Does Boost.Log support logging at process initialization and termination?
PrevUpHomeNext

It should be fine to use logging during the application initialization (i.e. before main() starts). But there are a number of known problems with Boost.Log that prevent it from being used at process termination (i.e. after the main() function returns), so the official answer to the second part is no. It may work though, in some very restricted setups, if several rules are followed:

  • Do not create any objects at process termination, including loggers, attributes or sinks. Try to create and cache the required objects as soon as the application starts (maybe even before main() starts).
  • Do not use global loggers at process termination.
  • Do not call logging::core::get() at process termination. Get that pointer as early as possible and keep it until the process terminates.
  • Do not use named scopes in termination code.

These rules don't guarantee that the library will work in termination context but they may help to avoid problems. The library will get improved to support this use case better.


PrevUpHomeNext