feat(examples)(client): updates to work with new logging ownership

This commit is contained in:
illyum 2024-09-16 23:28:09 -06:00
parent b17c160d5c
commit 8489b1e3a2

View File

@ -9,6 +9,7 @@ void ShowLogger();
int main() { int main() {
ShowLogger(); ShowLogger();
ICEngine::StartApplication();
return 0; return 0;
} }
@ -34,11 +35,15 @@ void ShowLogger() {
// You can have multiple log streams, ie console + file etc // You can have multiple log streams, ie console + file etc
// You do not need to have the same streams for each logger // You do not need to have the same streams for each logger
#include <fstream> #include <fstream>
std::ofstream coreFileStream("core_logs.txt"); // Create file streams and transfer ownership to the logger
std::ofstream appFileStream("app_logs.txt"); // You need to create a unique pointer, because the logger will
// take ownership of the streams and clean them up when the app
// is complete
auto coreFileStream = std::make_unique<std::ofstream>("core_logs.txt");
auto appFileStream = std::make_unique<std::ofstream>("app_logs.txt");
ICEngine::Log::GetCoreLogger()->AddStream(&coreFileStream); ICEngine::Log::GetCoreLogger()->AddStream(std::move(coreFileStream));
ICEngine::Log::GetAppLogger()->AddStream(&appFileStream); ICEngine::Log::GetAppLogger()->AddStream(std::move(appFileStream));
// You can log multiple different types with formatting // You can log multiple different types with formatting
int age = 30; int age = 30;
@ -68,4 +73,15 @@ void ShowLogger() {
// LOG_FATAL: Logs a fatal error in the application layer. This will trigger the Fatal Handler, which you can override // LOG_FATAL: Logs a fatal error in the application layer. This will trigger the Fatal Handler, which you can override
// The Fatal Handler provides a mechanism for handling unrecoverable errors gracefully, allowing you to define how the application reacts to fatal crashes // The Fatal Handler provides a mechanism for handling unrecoverable errors gracefully, allowing you to define how the application reacts to fatal crashes
// LOG_FATAL("This is an example of log fatal crash!"); // LOG_FATAL("This is an example of log fatal crash!");
} }
class DemoApp : public ICEngine::ICEApplication {
public:
void Run() override {
LOG_TRACE("Running demo app!");
}
};
ICEngine::ICEApplication* ICEngine::CreateICEApplication() {
return new DemoApp();
}