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...) ?


回答1:


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

http://www.boost.org/doc/libs/1_57_0/libs/log/doc/html/log/detailed/utilities.html#log.detailed.utilities.setup.settings_file


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):

[Sinks.MySink]
Destination=Console
Format="%LineID%: <%Severity%> - %Message%"

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

http://boost.2283326.n4.nabble.com/log-init-from-settings-problem-with-applying-format-and-filter-td3643483.html

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):

http://www.boost.org/doc/libs/1_57_0/libs/log/doc/html/log/extension/settings.html

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.



来源:https://stackoverflow.com/questions/25845154/boost-log-configuration-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!