Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do C++ logging frameworks sacrifice reusability?

In C++, there isn't a de-facto standard logging tool. In my experience, shops roll their own. This creates a bit of a 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 take your logging framework along with the components they really want.

IOC (dependency injection) doesn't really help with the problem since your components would need to depend on a logging abstraction. Logging components themselves can add dependencies on file I/O, triggering mechanisms, and other possibly unwanted dependencies.

Does adding a dependency to your proprietary logging framework sacrifice the reusability of the component?

like image 292
Joe Schneider Avatar asked Apr 24 '26 08:04

Joe Schneider


1 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 are just dependent on the abstract base-class. And you inject the implementations along with al their dependencies as needed.

like image 158
Mendelt Avatar answered Apr 27 '26 00:04

Mendelt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!