Are C ++ features needed for logging?

In C ++, there is no standard de facto logging tool. In my experience, stores are folding their own. This poses some problem, however, when trying to create reusable software components. If everything in your system depends on the logging component, this makes the software less reusable, basically forcing any downstream projects to use your logging system along with the components that they really want.

IOC (dependency injection) does not really help with the problem, since your components will have to depend on the registration paragraph. Logging components can add file I / O dependencies, startup mechanisms, and other possible unwanted dependencies.

Does dependence on your own logging structure increase the ability to reuse a component?

+3
source share
3 answers

Yes. But dependency injection will help in this case.

You can create an abstract logging base class and create implementations for the logging frameworks you want to use. Your components simply depend on an abstract base class. And if necessary, you add implementations along with your dependencies.

+5

, . . ILogger, . DLL Logger .

+1

, , , , , - ( ) .

, - , , .

, , , .

In addition, the calling user may have built-in components from the library several times, as well as problems with resource conflicts or threads, you want to provide a different log response for each of them.

0
source

Source: https://habr.com/ru/post/1696634/


All Articles