mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-09 21:44:54 +00:00
Add log sinks (stdout and file)
This commit is contained in:
parent
84949bedb1
commit
c3298d13a6
@ -193,7 +193,9 @@ namespace MWWorld
|
|||||||
navigatorSettings.mNavMeshPathPrefix = Settings::Manager::getString("nav mesh path prefix", "Navigator");
|
navigatorSettings.mNavMeshPathPrefix = Settings::Manager::getString("nav mesh path prefix", "Navigator");
|
||||||
navigatorSettings.mEnableRecastMeshFileNameRevision = Settings::Manager::getBool("enable recast mesh file name revision", "Navigator");
|
navigatorSettings.mEnableRecastMeshFileNameRevision = Settings::Manager::getBool("enable recast mesh file name revision", "Navigator");
|
||||||
navigatorSettings.mEnableNavMeshFileNameRevision = Settings::Manager::getBool("enable nav mesh file name revision", "Navigator");
|
navigatorSettings.mEnableNavMeshFileNameRevision = Settings::Manager::getBool("enable nav mesh file name revision", "Navigator");
|
||||||
DetourNavigator::Log::instance().setEnabled(Settings::Manager::getBool("enable log", "Navigator"));
|
if (Settings::Manager::getBool("enable log", "Navigator"))
|
||||||
|
DetourNavigator::Log::instance().setSink(std::unique_ptr<DetourNavigator::FileSink>(
|
||||||
|
new DetourNavigator::FileSink(Settings::Manager::getString("log path", "Navigator"))));
|
||||||
mNavigator.reset(new DetourNavigator::Navigator(navigatorSettings));
|
mNavigator.reset(new DetourNavigator::Navigator(navigatorSettings));
|
||||||
|
|
||||||
mRendering.reset(new MWRender::RenderingManager(viewer, rootNode, resourceSystem, workQueue, &mFallback, resourcePath, *mNavigator));
|
mRendering.reset(new MWRender::RenderingManager(viewer, rootNode, resourceSystem, workQueue, &mFallback, resourcePath, *mNavigator));
|
||||||
|
@ -6,11 +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 <chrono>
|
#include <chrono>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -33,36 +33,64 @@ namespace DetourNavigator
|
|||||||
<< std::chrono::duration_cast<float_s>(value.time_since_epoch()).count();
|
<< std::chrono::duration_cast<float_s>(value.time_since_epoch()).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Log
|
struct Sink
|
||||||
|
{
|
||||||
|
virtual ~Sink() = default;
|
||||||
|
virtual void write(const std::string& text) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileSink final : public Sink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Log()
|
FileSink(std::string path)
|
||||||
: mEnabled()
|
: mPath(std::move(path))
|
||||||
{
|
{
|
||||||
mFile.exceptions(std::ios::failbit | std::ios::badbit);
|
mFile.exceptions(std::ios::failbit | std::ios::badbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEnabled(bool value)
|
void write(const std::string& text) override
|
||||||
{
|
{
|
||||||
mEnabled = value;
|
if (!mFile.is_open())
|
||||||
|
{
|
||||||
|
mFile.open(mPath);
|
||||||
|
}
|
||||||
|
mFile << text << std::flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string mPath;
|
||||||
|
std::ofstream mFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
class StdoutSink final : public Sink
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void write(const std::string& text) override
|
||||||
|
{
|
||||||
|
std::cout << text << std::flush;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Log
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void setSink(std::unique_ptr<Sink> sink)
|
||||||
|
{
|
||||||
|
const std::lock_guard<std::mutex> guard(mMutex);
|
||||||
|
mSink = std::move(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEnabled() const
|
bool isEnabled() const
|
||||||
{
|
{
|
||||||
return mEnabled;
|
const std::lock_guard<std::mutex> guard(mMutex);
|
||||||
|
return bool(mSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const std::string& text)
|
void write(const std::string& text)
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
const std::lock_guard<std::mutex> guard(mMutex);
|
||||||
{
|
if (mSink)
|
||||||
const std::lock_guard<std::mutex> lock(mMutex);
|
mSink->write(text);
|
||||||
if (!mFile.is_open())
|
|
||||||
{
|
|
||||||
mFile.open("detournavigator.log");
|
|
||||||
}
|
|
||||||
mFile << text << std::flush;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Log& instance()
|
static Log& instance()
|
||||||
@ -72,9 +100,8 @@ namespace DetourNavigator
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex mMutex;
|
mutable std::mutex mMutex;
|
||||||
std::ofstream mFile;
|
std::unique_ptr<Sink> mSink;
|
||||||
std::atomic_bool mEnabled;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void write(std::ostream& stream)
|
inline void write(std::ostream& stream)
|
||||||
|
@ -597,6 +597,9 @@ triangles per chunk = 256
|
|||||||
# Enable debug log (true, false)
|
# Enable debug log (true, false)
|
||||||
enable log = false
|
enable log = false
|
||||||
|
|
||||||
|
# Write debug log to this file
|
||||||
|
log path = detournavigator.log
|
||||||
|
|
||||||
# Write recast mesh to file in .obj format for each use to update nav mesh (true, false)
|
# Write recast mesh to file in .obj format for each use to update nav mesh (true, false)
|
||||||
enable write recast mesh to file = false
|
enable write recast mesh to file = false
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user