Boost.Log Configuration Files

爷,独闯天下 提交于 2019-12-04 19:25:25


I'm adding logging to an old C++ program. After some research, I've decided to use Boost Log . The documentation is filled with examples of creating sinks and filters. However, I couldn't find any example of a log configuration file.

Is there a way to configure logging from a file that doesn't have to be compiled? Similar to what log4net has? Or Python (well, since Python isn't compiled, anyway...) ?


Eventually I found the official documentation, either it was added recently, or it is well hidden so that I didn't see it before:

Unfortunately, I can't find an exhaustive answer neither, but some observations:

Certainly it is possible to use a configuration file:

boost::log::init_from_stream(std::basic_istream< CharT > &)

Example of the file (from Boost log severity_logger init_from_stream):

Format="%LineID%: <%Severity%> - %Message%"

From the following link you can identify additional valid setting keys and values (e.g. Destination=TextFile, Filter=, AutoFlush=, FileName=)

Constants in boost's parser_utils.hpp give another idea of keywords that are by default supported by the configuration file (E.g. section [Core] with key DisableLogging).

Providing settings for user defined types is described here (with a corresponding snippet of the configuration file at the end of the page):

It seems to me that it is difficult to find a description of the configuration file format entries because the valid entries are derived from the source code implementing the sinks, filters etc. This implementation may be even user defined so it is impossible to give explicit configuration format description.

Maybe you can try to create your configuration in a programmatic way and when transforming it to the form of the configuration file, you can open separate questions for the particular properties that you are not able find out how to set them.