user13295228
user13295228

Reputation:

Where to insert the filtering logging mechanism when using Boost.Log V2 module?

I have a project organized as follows:

enter image description here

All the "component" folders have the same structure. I am using the Boost.Log v2, and I am able to see all types of logs (trace, debug, ..., fatal) on the console, when I use them. I would like to use the very basic filtering mechanism shown in the documentation:

enter image description here

Here, a function "init" is called to perform the filtering. My question is: where is the correct place to put this filtering, in the case of my project, in such a way it will be valid everywhere in the project itself and if I need to change the default severity I would need to modify the code in just one place? Do I need like a configuration file where to put it? I was thinking to put it in every main.cpp inside every component but I think there are best solutions to do that. Thanks in advance.

Upvotes: 0

Views: 51

Answers (1)

Andrey Semashev
Andrey Semashev

Reputation: 10614

There is only one main function per process. You need to initialize logging, including filtering, early in that function.

If your project has multiple different executables then each executable has its own main function and you need to perform logging initialization in each of them. If you want to avoid code duplication, you can move the initialization to a common header and/or library that you would use in each of the executables. For example, move the init function from your code snippet to a separate header and include and use it in every main function.

You can use settings files with Boost.Log, but that is entirely unrelated to code organization.

Upvotes: 1

Related Questions