#include#include "Logger.h" using namespace std; int main() { Logger myLogger; myLogger.addMessage("Debug Statement: Initializing application..."); myLogger.addMessage("Info Statement: User logged in successfully"); myLogger.addMessage("Error Statement: Invalid input provided"); return 0; }
#includeIn this example, we have a Logger instance as a private member of a class. We then call the "addMessage" function inside a function of that class. This could be useful for logging messages related to specific class instances and their functions. The package or library for the Logger class in these examples is not explicitly stated, as it will depend on the implementation. However, there are many logging libraries available for C++ such as Boost.Log and Log4cxx.#include "Logger.h" using namespace std; class MyClass { private: Logger myLogger; public: void myFunction() { myLogger.addMessage("Debug Statement: Entered myFunction"); // rest of the code } }; int main() { MyClass obj; obj.myFunction(); return 0; }