From 794cfc4aa3923d609c553083648df83a89c20e41 Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 4 Apr 2018 01:10:43 +0300 Subject: [PATCH] Write detournavigator log to file --- components/detournavigator/debug.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/components/detournavigator/debug.hpp b/components/detournavigator/debug.hpp index 2a9f851a3..520851fbe 100644 --- a/components/detournavigator/debug.hpp +++ b/components/detournavigator/debug.hpp @@ -6,8 +6,11 @@ #include #include +#include +#include #include #include +#include #include #include @@ -25,7 +28,11 @@ namespace DetourNavigator class Log { public: - Log() : mEnabled(false) {} + Log() + : mEnabled() + { + mFile.exceptions(std::ios::failbit | std::ios::badbit); + } void setEnabled(bool value) { @@ -40,7 +47,14 @@ namespace DetourNavigator void write(const std::string& text) { if (mEnabled) - std::cout << text; + { + const std::lock_guard lock(mMutex); + if (!mFile.is_open()) + { + mFile.open("detournavigator.log"); + } + mFile << text << std::flush; + } } static Log& instance() @@ -50,7 +64,9 @@ namespace DetourNavigator } private: - bool mEnabled; + std::mutex mMutex; + std::ofstream mFile; + std::atomic_bool mEnabled; }; inline void write(std::ostream& stream)