1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 10:23:52 +00:00

Write detournavigator log to file

This commit is contained in:
elsid 2018-04-04 01:10:43 +03:00
parent dd5e6a61a3
commit 794cfc4aa3
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40

View file

@ -6,8 +6,11 @@
#include <components/bullethelpers/operators.hpp> #include <components/bullethelpers/operators.hpp>
#include <components/osghelpers/operators.hpp> #include <components/osghelpers/operators.hpp>
#include <atomic>
#include <fstream>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <mutex>
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -25,7 +28,11 @@ namespace DetourNavigator
class Log class Log
{ {
public: public:
Log() : mEnabled(false) {} Log()
: mEnabled()
{
mFile.exceptions(std::ios::failbit | std::ios::badbit);
}
void setEnabled(bool value) void setEnabled(bool value)
{ {
@ -40,7 +47,14 @@ namespace DetourNavigator
void write(const std::string& text) void write(const std::string& text)
{ {
if (mEnabled) if (mEnabled)
std::cout << text; {
const std::lock_guard<std::mutex> lock(mMutex);
if (!mFile.is_open())
{
mFile.open("detournavigator.log");
}
mFile << text << std::flush;
}
} }
static Log& instance() static Log& instance()
@ -50,7 +64,9 @@ namespace DetourNavigator
} }
private: private:
bool mEnabled; std::mutex mMutex;
std::ofstream mFile;
std::atomic_bool mEnabled;
}; };
inline void write(std::ostream& stream) inline void write(std::ostream& stream)